Questions tagged [cp]
Questions relating to the Linux 'cp' command.
225
questions
1329
votes
8
answers
4.0m
views
How can I copy the contents of a folder to another folder in a different directory using terminal?
I am trying to copy the contents of a folder to another folder in a different directory using terminal.
Would somebody be able to provide me an example of the command line syntax required to achieve ...
477
votes
7
answers
1.3m
views
What does "cp: omitting directory" mean?
I've issued the following command:
sudo cp ~/Transfers/ZendFramework-1.11.4-minimal/library/Zend/* ~/public_html/cmsk.dev/library/
When I do this, I start getting the following messages:
cp: ...
125
votes
7
answers
660k
views
how do you copy a directory and its contents to a new location under a new directory name?
I'm new to the Linux command line and am trying to get to grips with the copy command at the moment.
Can anyone please tell me if it's possible to copy a directory with its subdirectories and ...
113
votes
3
answers
181k
views
Copy a file and keep the same timestamp of the original file
I need to a copy file and after that I need to change the timestamp attributes as the original file. How can I do it with the terminal or any other way?
101
votes
10
answers
169k
views
How to copy a file to multiple folders using the command line?
I have tried to copy a file test.txt to multiple directories with one command:
cp ~/test.txt ~/folder1 ~/folder2
But I didn't succeed. Is there a way to do that in one command so I can copy a file ...
77
votes
5
answers
222k
views
cp command to exclude certain files from being copied
Is there a way to use the cp command to copy a directory and exclude certain files/sub-directories within it?
64
votes
5
answers
202k
views
Can I verbose output during a copy command processing?
Situation: If I entered a copy command like cp -rf /src/ /dsc/ then I am waiting several minutes for copy large directories. I forgot to put -v flag to verbose an output, Can I do it during copying?
42
votes
5
answers
593k
views
cp - cannot create regular file : permission denied
I want copy to /lib/udev but gives error
cp -f /tmp/ok_pcscd_hotplug.sh /lib/udev
cp:cannot create regular file /lib/udev/ok_pcscd_hotplug : Permission denied
I am root , but I can't understand . ...
28
votes
2
answers
84k
views
Copy the content/file to all subdirectory in a directory using terminal
I want to copy a file to all subfolders in a folder. How can I do this with the command line?
24
votes
2
answers
62k
views
Is there any way to create backup copy of a file, without type its name twice? [duplicate]
Often when I'm editing some system file first I create a backup copy. For example:
sudo cp /etc/ssh/sshd_config /etc/ssh/sshd_config.bak
Is there any simple 'shortcut' such as:
sudo cp /etc/ssh/...
24
votes
2
answers
57k
views
force cp to copy on dangling symlinks
Is there any way to force cp (Bash 4.2.5, Ubuntu 12.04) to copy onto a dangling symlink?
cp a-file path/to/danling/symlink/a-file
cp: not writing through dangling symlink `path/to/danling/symlink/a-...
23
votes
2
answers
46k
views
Copy only folders not files?
Is there a way to copy an entire directory, but only the folders? I have a corrupt file somewhere in my directory which is causing my hard disks to fail.
So instead of copying the corrupt file to ...
21
votes
3
answers
77k
views
How to copy a directory from one hard drive to another with every single file?
I have a folder I just luckily recovered sitting on:
/media/sdc1/Pictures
with a BUNCH of subdirectories and files that I need.
I want to copy these to a folder on:
/media/sdb1/Pictures
What ...
21
votes
2
answers
42k
views
What's the difference between ` cp ` and ` rsync `? [closed]
They seem similar to me. I want to know how to use them. What's the difference in structure?
18
votes
2
answers
109k
views
Ubuntu copying file problem (cannot stat file)
I've faced a problem when copying a file with the commands,
cp ~/Downloads/sample.pdf ~/Desktop/
But the terminal gives me a message, cp: cannot stat 'sample.pdf': No such file or directory.
17
votes
1
answer
26k
views
What is the difference in using cp and dd when cloning USB sticks?
I found that there are at least two methods to clone a USB stick:
(with /dev/sdb as the source while /dev/sdc the target)
Cloning with cp:
sudo cp /dev/sdb /dev/sdc
Cloning with dd:
sudo dd if=/...
15
votes
8
answers
10k
views
Copy group of files (Filename*) to backup (Filename*.bak)
Background
In Linux you can:
List a group of files with ls Filename*
Remove a group of files with rm Filename*
Move a group of files with mv Filename* /New/Directory
But you cannot copy a group of ...
15
votes
5
answers
90k
views
Recursively copy files from one directory to another
I have all my music in a folder /media/kalenpw/MyBook/Music/ABunchOfOtherFoldersWithFilesInside. I want to copy all of the mp3s to /media/kalenpw/HDD/Music so I used:
cp -R /media/kalenpw/MyBook/...
14
votes
5
answers
61k
views
Undo copy (cp) command action
I copied some file from source folder into destination folder by using bellow command line in terminal.
sudo cp From_SOURCE/* To_DESTINATION/
Now I want to undo this command.
12
votes
1
answer
2k
views
Overwritten /usr/share/bin. Am I doomed?
I just managed to overwrite /usr/share/bin
and it doesn't seem like it's possible to undo.
I did this as a root user.
Am I doomed?
12
votes
3
answers
116k
views
cp fails to copy with errors "cp: error reading 'file': Input/output error" and "cp: failed to extend 'file': Input/output error
I'm a user of Oracle Virtualbox on Ubuntu. And I used to copy vdi files as a kind of backup. Previously I did this (copying vdi file and then copying it back) many times without any problem.
But ...
11
votes
5
answers
38k
views
What is the difference between scp and cp?
I'm really new to the command line and Ubuntu and I have recently learned that there is the scp command as well as the cp command. I tried to use an scp command to move a directory from Point A to ...
11
votes
2
answers
72k
views
Copying files from directories having spaces in its name
This is what I tried.
inputFile=$(zenity --file-selection --title "Test" --text "Please select the file for analysis." | sed -e "s/ /\\\ /g")
I did the sed operation to replace white spaces with a \...
10
votes
3
answers
63k
views
Why won't my cp command copy whole directories? [duplicate]
I've tested the cp command, and it will only copy individual files. For example, I typed cp followed by the exact filename, then typed the directory and the file got copied. However, when I typed the ...
10
votes
4
answers
8k
views
How to copy into with cp if destination folder already exists?
Example...
This is what I want.
/tmp $ cp -f -R --verbose /tmp/a /tmp/b
`/tmp/a' -> `/tmp/b'
`/tmp/a/file2' -> `/tmp/b/file2'
`/tmp/a/file1' -> `/tmp/b/file1'
This is what I do not want.
/...
10
votes
2
answers
3k
views
Copy and paste a bunch of files with different name
I have a bunch of text files with the name
foo_bar_abc_1_01_geh_original.in
foo_bar_abc_1_02_geh_original.in
foo_bar_abc_1_03_geh_original.in
...
...
foo_bar_abc_1_1000_geh_original.in
I would like ...
10
votes
4
answers
40k
views
copy/move multiple files using cp/mv without using regular expressions
Suppose I have a folder containing some files and some folders(files can be of any type). And I want to move/copy some of those files and folders using mv/cp command. Is there any way, such that I ...
10
votes
2
answers
20k
views
How do I copy a directory into itself?
I can copy a directory like so:
~$ cp -r ./Desktop/ /tmp/
Similarly, if I just wanted to copy the files from within a directory, I could do so:
~$ cp -r ./Desktop/. /tmp/
Things become a little ...
9
votes
3
answers
9k
views
How to rename file names to avoid conflict in Windows or Mac?
How can I batch rename file names so that they do not include characters that clash with other file systems as for instance,
Screenshot 2015-09-07-25:10:10
Note that the colons are the issue in ...
8
votes
2
answers
4k
views
cp recursive with specific file extension
I am trying to copy all .odt files including those in subdirectories.
cp -r ~/Documents/* ~/copies # works as expected
cp -r ~/Documents/*.odt ~/copies # does not work as expected
The first line ...
8
votes
1
answer
77k
views
What does "omitting directory" mean and how do I make it cp the directory rather than omit it
I am doing a data recovery for someone and enter the following command
-Ubuntu:~# cp /media/Macintosh\ HD/Users/orlando/Desktop\ (original)/VIDEOS\ ESPANOL/ /media/\$G\$\ DATA/Orlando/Desktop/
And ...
8
votes
2
answers
15k
views
How to copy an entire directory except one file in each sub-directory via terminal? [duplicate]
I have a folder named 'Java' which has 20 sub folders ('Day-01' to 'Day-20'). Each sub folder has one or two '.wav' files along with few other files. I want to copy the entire directory except the '....
7
votes
1
answer
2k
views
Why does "cp" complain about identical files when chaining with "find"?
I have a find command as below that lists the matching files:
$ find . -type f -name "*.txt"
./level2/file2.txt
./level2/level3/file3.txt
./level2/level3/level4/file4.txt
./level2/level3/...
7
votes
5
answers
9k
views
trying to CP a directory to /dev/null
What I'm really tring to do, it verify the the data on an external drive is still readable. I thought the simplest and surest way to do this would be to copy everything to /dev/null. It works great ...
6
votes
2
answers
2k
views
What does the -rd option mean in the cp command?
I have found a reference using the following command
cp -rd * /folder_1/
and another one as
cp -dr * /folder_2/
Can you please advise what are these options "rd" or "dr"?
6
votes
4
answers
34k
views
copy two files at a time
What to do if I want to copy two file at a time using command ? let's say I have one folder named ABC and files are
mno.txt
xyz.txt
abcd.txt
qwe.txt and so on (100 no. of files)
Now I want to cp ...
6
votes
1
answer
6k
views
How can I copy a directory without copying a specific file or subdirectory in terminal?
I have a directory main_dir which contains lots of files and 3 subdirectories (dir1 and dir2 and dir3). I want to copy it to another location without copying dir2 in one command. I searched the cp ...
6
votes
2
answers
3k
views
How can I duplicate a file x times in a different directory with terminal?
I am trying to duplicate an image file to a different folder x times (100 times). How can I do this in the terminal?
I succeeded in duplicating in same folder, but I need to duplicate in another ...
6
votes
4
answers
55k
views
External backup - "cp: cannot create regular file" error
I have always backed up my home directory to an external hard drive using the cp -r command.
Until recently, it worked fine, but now I regularly get the error message cp: cannot create regular file ...
6
votes
2
answers
7k
views
Using mv & cp on a headless server (SSH timeout interferring?)
I've recently set up a headless server to back up a number of very large film & editing files.
I SSH into the server and - following some best practice guides I found around - I've tightened ...
6
votes
1
answer
64k
views
cp: cannot create regular file: Read-only file system
I have an bootable flash-card (with acronis (not my installation)), I may read but cannot copy file into it.
When I uses windows, then I not have any problem, but I cannot use this card in ubuntu - ...
6
votes
3
answers
22k
views
Why does cp not copy files?
$ ls -la /tee/mysql
total 28675
drwxrwxrwx 1 root root 448 Jun 25 13:52 .
drwxrwxrwx 1 root root 2896 Jun 25 12:12 ..
-rwxrwxrwx 1 root root 18874368 Jun 25 13:19 ibdata1
-rwxrwxrwx 1 root ...
6
votes
1
answer
921
views
High copy speed at begining of copying
When I copy file (doesn't mater which process I use - krusader, cp, dd, ...) firstly its very fast, like way too fast (around 7000 MB/s to USB 2.0 pen-drive). Then it suddenly slows down (usually at ...
6
votes
1
answer
5k
views
How do I exclude a specific extension from recursive file copying?
I want to copy all of the files and subdirs except the data file which named *.data to a destination dir.
[ichen@ui01 sub_test]$ ls
a.cxx a.data subdir
[ichen@ui01 sub_test]$ ls subdir/
sub_a.cxx ...
5
votes
2
answers
3k
views
sh alternative to bash cp {file,file}
In a script, if I put #!/bin/bash at the top, this will work fine:
cp directory/{foo,bar} destination
However, with sh, this will give the error 'no such file or directory'. In sh, is there another ...
5
votes
1
answer
3k
views
Copy large number of files of specific date to another directory?
I've around 11K log files of specific date let say 26Feb inside one directory(there are other date data also). To copy only 26th Feb log files to destination from linux command line, I use below ...
5
votes
4
answers
37k
views
How can I copy the contents of a child folder to its parent folder using command line?
I have this directory structure:
parent_folder/child_folder/
I want to copy the contents of the child folder to the parent folder, but I don't know how to do it with cp.
4
votes
2
answers
1k
views
Copying directories in linux only if it contains the specified file
I need to make a copy of all the folders under /parent (into a new location) but only if it has 123.dat - in which case I need to copy the folder too, but none of the other files it contains.
So that ...
4
votes
2
answers
5k
views
Make multiple copies of one file with different names
How can I create multiple file from one?
Like, I have 1.json, but want to create 2.json + 3.json + 4.json out of it.
Most obvious way is to just cp 1.json 2.json and so on; but does Linux provide some ...
4
votes
1
answer
10k
views
cp Cannot Stat '-r'
Strange issue, for some reason, when I'm running a copy command, it's treating the -r flag as an argument.
sudo cp –r usr/* /usr
The following is the error:
cp: cannot stat ‘–r’: No such file or ...