cp is the command of the Unix operating system that is used to copy files.

learn more… | top users | synonyms

76
votes
6answers
58k views

How to copy with cp to include hidden files and hidden directories and their contents?

How can I make cp -r copy absolutely all of the files and directories in a directory Requirements: Include hidden files and hidden directories. Be one single command with an flag to include the ...
55
votes
6answers
88k views

How to copy symbolic links?

I have directory that contains some symbolic links: user@host:include$ find .. -type l -ls 4737414 0 lrwxrwxrwx 1 user group 13 Dec 9 13:47 ../k0607-lsi6/camac -> ../../include 4737415 ...
35
votes
8answers
3k views

Why is -r recursive necessary when copying a directory in Linux?

My question is why is it required to use the -r (recursive) flag when making a copy of a directory? I.e., why do this: $ cp -r dir1 copyDir1 When would I not want this behavior when copying a ...
33
votes
4answers
29k views

How can I recursively copy files by file extension, preserving directory structure?

At the Linux command line, I'd like to copy a (very large) set of .txt files from one directory (and its subdirectories) to another. I need the directory structure to stay intact, and I need to ...
13
votes
3answers
295 views

Reuse text on a bash command

If i'm writing a long command or just typing an extensive file path, is there any that i can "reuse" it with some command shortcut? e.g: 1.cp /home/myuser/really/big/file/here/and/there.png ...
13
votes
4answers
10k views

How to copy symlinks to target as normal folders

i have a folder with symlinks: marek@marek$ ls -al /usr/share/solr/ razem 36 drwxr-xr-x 5 root root 4096 2010-11-30 08:25 . drwxr-xr-x 358 root root 12288 2010-11-26 12:25 .. drwxr-xr-x 3 root ...
12
votes
3answers
24k views

Copy list of files

I have a list of files separated by spaces in a file list.txt. I'd like to copy them to a new folder. I tried to do: cp `cat list.txt` new_folder but it did not work. How would you do this ? ...
10
votes
3answers
2k views

How is install -c different from cp

What is the difference between install -c and cp? Most installations tend to use install -c, but from the man page it doesn't sound like it does anything different than cp (except maybe set ...
8
votes
5answers
43k views

Copying files with SSH

I am trying to copy a file from my other computer, to another computer. (both running Ubuntu 9.10) So say: I've ssh'ed into the other computer; i 'cd' to the directory; and i entered cp File.zip ...
7
votes
5answers
9k views

How can I copy a (big) directory over another changing only the files that differ?

I have directory a and directory b. They are big. b is almost identical to a. "almost" means that 4-5 files differ, and I don't know which they are. I want to copy b over a, but only the files that ...
7
votes
3answers
8k views

Copy file in GNU/Linux with progress bar and rate limiting

Is there any good tool in GNU/Linux that copy files like cp, but also shows progress and limits speed (and changes limit without interruption) like pv? Prototype: find source_directory | cpio -H ...
6
votes
4answers
3k views

Linux copy to fat32 filesystem: invalid argument

When I copy files from an ext3 partition to a fat32 one using cp: cp -R /ext3/stuff /fat32/partition/ I get invalid argument messages for all files with colons and question marks in. Is there any ...
6
votes
3answers
11k views

how to stop cp: overwrite './xxx' ? prompt

How can I stop the cp command from prompting to overwrite. I want to overwrite all the files with out having to keep going back to the terminal. As these are large files and take some time to ...
6
votes
2answers
6k views

How do you use regular expressions with the cp command in Linux?

I am attempting to only copy a subset of files from one directory to another using cp however am greeted with the message cp: cannot stat [^\.php]': No such file or directory. Is there a way to use ...
6
votes
5answers
5k views

How can I use cp to copy a directory but ignore a certain sub directory in Linux

Due to a Hard disk problem I am trying to shift a partition from one hard disk to another. I am following http://www.ibm.com/developerworks/library/l-partplan.html article to do that. In the copying ...
5
votes
5answers
4k views

cp -r -l in MacOS (recursive copy preserving hard links)

I'm trying to copy a directory tree recursively preserving hardlinks to the file. Using gnu cp, this would work with the -l flag. cp would then recreate the directory structure, but wouldn't need to ...
5
votes
2answers
9k views

Use rsync to copy all files except for certain filenames with a certain extension

I have two same-size flash cards, and I want to copy contents of one to the other based on the following rules: I want all directories and subdirectories in place I want to exclude files of type ...
5
votes
1answer
1k views

Why does du -sl show different sizes for the source and result of a cp -rl?

I have used cp -rl to copy a folder. When measuring the size of the source and of the result of the copy du -sl returns slightly different sizes, even though diff confirms that their content are ...
4
votes
2answers
9k views

Linux permissions and owner being preserved with cp

I can't understand the following behavior: I have a file named someFile under /opt/com/internal/someFile If I do ls -all /opt/com/internal/someFile the permissions are 700 user:userGroup I am root ...
4
votes
3answers
1k views

Multi-core and copy speed

What i want to do is to copy 500K of files. I want to copy within server from one destination to another.It includes emails mostly so many small files. Its over 23 GB only but takes so long (over ...
4
votes
4answers
132 views

Why does “cp -r a/. b” behave as it does?

I thought that a and a/. is the same path. However, I've found that cp and rsync copy directory content instead of directory itself when /. is added to the source path. I also tried a/inner/..; this ...
3
votes
7answers
903 views

How do I make “cp” in OS X not delete files?

Here's the best way to describe this: dirA dir1 file1.txt file3.txt dirB dir1 file1.txt file2.txt I want to copy the contents of dirB into dirA. cp -R dirB/* dirA ...
3
votes
2answers
6k views

Copying many files without stopping on errors on OSX

I need to copy several Gb from an external HD to my moan hd and some files will cause errors. If I do this with the finder, it will stop on the first error. Is there a way to copy everything no ...
3
votes
2answers
2k views

cp command to make bootable iso image usb

A lot of discussions exist here on making a bootable USB stick. Debian manual on installing Wheezy suggest the following: # cp debian.iso /dev/sdX # sync Making sure the USB device is first ...
3
votes
1answer
5k views

Why do we use cp to copy files and not dd? (in unix-derivatives)

For normal file copying in *nix, I've only ever seen people use cp (eg. cp /mnt/mydevice/myfile ~/myfile), but I eventually ran into dd, which appears to do the exact same thing (dd ...
3
votes
3answers
1k views

How to copy one file into multiple subfolders at once on a Linux server?

I have a folder on a Linux server with 35+ subdirectories, along the lines of: aa.foo.bar.baz ab.foo.bar.baz .. bp.foo.bar.baz I have a file that I want to copy into each of those subdirectories. ...
3
votes
3answers
3k views

Linux: Copy all files by extension to single dirrectory

I am trying to copy all *.tif files from ./old to the ./new. In ./old i have lots of subdirs with different files, and in ./new i need only TIF files, without folder tree. So, I had tried cp -vR ...
3
votes
2answers
2k views

cp - do not overwrite in makefile

In the makefile for my project, I want it to copy a config file only if the file does not already exist in the destination folder. At the moment I am using: cp -n However, recently someone has ...
3
votes
3answers
6k views

How do I use find to copy all found files to a new name in their same directories?

I've got a simple command that does almost what I want. The following will locate all files with a suffix of '_compressed.swf' and copy each into its same directory with a '.bak2' appended: find ...
3
votes
4answers
1k views

Using cp command in linux shell, how do I copy a whole directory into another directory?

I have a directory, let's say, "work": ~/work/ This directory has some sub-folders (d1, d2...) in it and files in these sub-folders. I want to make a backup copy in the same folder, so it would be ...
3
votes
1answer
1k views

How can I avoid that cp freezes my OS?

I am using cp to copy data like so: cp -r from_here to_there When I do that, my computer freezes and unfreezes periodically. I have 4 CPUs installed and the HD is connected via SATA. from_here and ...
3
votes
1answer
516 views

How to preserve file-create-timestamp while copying files on OS X from command-line?

On OS X when you a copy a file using Finder, the target file has the same creation and modification times as the source file. However when you do so using cp in Terminal both creation and ...
2
votes
1answer
2k views

Is there a shortcut for unix `cp` to copy a file to the current directory with the same filename?

I'm hoping there's a shorter way of copying a file from a given directory to the current working directory than typing cp /path/to/file.txt file.txt I tend to use this command a lot, and reiterating ...
2
votes
4answers
1k views

cp command force

currently there's a xxx dir already in /home/yyy I'm trying to overwrite it cp -fr ../xxx /home/yyy/ doesn't work still prompts me to overwrite the individual files. how do I fix it?
2
votes
3answers
321 views

Copied directory appears to become larger at destination

I have the following code as part of a shell script: while [ $(ps -ef | awk '{print $2}' | grep -F "$CPPID") ]; do sleep 10 awk -v "usbsize=$(/bin/df | grep -F $DEVICEMOUNTPOINTQ | awk ...
2
votes
1answer
597 views

Unix command for recursively copying files

I need a unix command for the following: Directory Structure /project /images /products /cup.jpg /laptop.jpg /designs /alpha.jpg ...
2
votes
3answers
15k views

cp: reading `filename': Input/output error WHY?

I wish to know what could be the possible cases for this error: cp: reading `filename': Input/output error I am getting this message when I am trying to copy a big file of around 50MB.
2
votes
2answers
92 views

I somehow made our linux box's “CP” command act differently than the default, how can I revert it back to default?

Title explains it; Somehow in installing the 'z' directory jumper, I made our linux machines CP command act strangely (for example: it no longer prompts for overwrites, it auto-forces it whether we ...
2
votes
3answers
4k views

how to copy all files from one location to another in linux

I want to copy all the folders and files in the /var/www/ directory to another directory /media/magneto/ How do I do this? I tried this command cp -pRiv /var/www/ /media/magneto/ that didn't ...
2
votes
2answers
95 views

Recursive, Non-Overwriting Copy

I've got a directory that contains a bunch of other folders containing CoffeeScript/ JavaScript files. I'm able to compile the CoffeeScript files into a new folder with the same folder structure ...
2
votes
2answers
99 views

Why OSX cp -avr get this error: the -R and -r options may not be specified together?

I just want to copy a folder tree to another place like this: cp -avr /blah/blah/htdocs ./ but I got error: cp: the -R and -r options may not be specified together. I followed this tutorial: ...
2
votes
2answers
84 views

Running cp -r ~/.ipython ~/some/path/.ipython a second time creates ~/some/path/.ipython/.ipython. How to prevent that?

I am using a script to copy directories to a specified location. When I run cp -r ~/.ipython ~/some/path/.ipython the .ipython dir is copied as expected to the specified location. But when I run this ...
2
votes
3answers
163 views

In Power SHell set alias cp to cp -v

I have cp for power shell. But I want to use cp in verbose mode without writing -v. So cp should be aliased to "cp -v" command. How to alias cp to "cp -v" in power shell?
2
votes
1answer
931 views

ssh Mac Unix: copy a file with special characters and spaces

I am remote logged into a Mac and trying to copy a music file from one directory to another, but I am getting an error. I think it's caused by spaces or special characters, but not sure. the file ...
2
votes
1answer
1k views

Don't copy files that cause an input/output error

When copying files from a faulty hd with cp, rsync, or scp, the faulty files which can't be read anymore are also partly copied to the destination directory. Is there an option to automatically skip ...
2
votes
1answer
110 views

copying a file to a hard link

I recently got bit by a misbehaving in a bash script of mine and was wondering: is this the expected system behavior, or is it a bug what are the ideal workarounds Essentially, the problem boiled ...
2
votes
1answer
90 views

Copy everything in a subdirectory across to the relevant subdirectory elsewhere

At the moment I'm doing: for i in mdx/[0-9][0-9].png; do cp $i ../../d_s_c/images/mdx ; done But as well as the directory mdx, I also have other directories called ntt, etc. How can I say 'For ...
2
votes
1answer
279 views

Symlink all files but copy certain extensions

I'm wondering how I'd be able to symlink all the files in a dir structure and then also copy files of a certain extension in that dir. I'm basically symlinking all files within /foo/a,b,c to ...
1
vote
1answer
51 views

Query on “cp” command

I have a directory say ~/MyWorks which contains the following files in it: a.c, b.c and c.c I want to copy the MyWorks directory to ~/MyAssignments such that only the directory MyWorks is copied and ...
1
vote
3answers
2k views

Copy multiple files via cp from a string

I'm trying to copy multiple files to a directory from within a shellscript. These files contain all sorts of "ugly" characters, such as whitespaces, brackets and what not else. However, I'm stuck when ...