Skip to main content

Questions tagged [cp]

Questions relating to the Linux 'cp' command.

Filter by
Sorted by
Tagged with
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 ...
pandisvezia's user avatar
  • 13.5k
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: ...
MEM's user avatar
  • 11.1k
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 ...
Edmuntu's user avatar
  • 1,263
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?
user avatar
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 ...
nux's user avatar
  • 38.2k
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?
Stephen Jacob's user avatar
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?
Smile.Hunter's user avatar
  • 8,395
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 . ...
user278122's user avatar
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?
22lk94k943 only's user avatar
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/...
pa4080's user avatar
  • 30.1k
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-...
Marcus Junius Brutus's user avatar
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 ...
Shannon's user avatar
  • 241
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 ...
wardr's user avatar
  • 2,319
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?
Thái Siu Nhưn's user avatar
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.
Herks's user avatar
  • 833
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=/...
MrWm's user avatar
  • 175
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 ...
WinEunuuchs2Unix's user avatar
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/...
kalenpw's user avatar
  • 744
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.
αғsнιη's user avatar
  • 35.9k
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?
user avatar
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 ...
d.k's user avatar
  • 437
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 ...
BDD's user avatar
  • 220
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 \...
Anonymous Platypus's user avatar
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 ...
user avatar
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. /...
James Mitch's user avatar
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 ...
phenomenon's user avatar
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 ...
MikhilMC's user avatar
  • 375
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 ...
Andrew Hardiman's user avatar
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 ...
don.joey's user avatar
  • 28.8k
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 ...
Insideup's user avatar
  • 115
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 ...
Zargold's user avatar
  • 217
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 '....
optimist's user avatar
  • 133
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/...
Isaac's user avatar
  • 173
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 ...
pastorbadger's user avatar
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"?
moibrahim's user avatar
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 ...
Avani badheka's user avatar
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 ...
ziadome's user avatar
  • 75
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 ...
Dio Pratama's user avatar
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 ...
Lolwhites's user avatar
  • 731
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 ...
Huw's user avatar
  • 1,603
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 - ...
Valentyn Hruzytskyi's user avatar
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 ...
msh210's user avatar
  • 115
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 ...
Jav's user avatar
  • 73
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 ...
spring cc's user avatar
  • 163
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 ...
Arrrow's user avatar
  • 153
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 ...
Achal's user avatar
  • 217
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.
Jatin Parmar's user avatar
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 ...
Chillax's user avatar
  • 143
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 ...
E1dar's user avatar
  • 151
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 ...
Dan Hanly's user avatar
  • 210

1
2 3 4 5