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

learn more… | top users | synonyms

57
votes
5answers
41k 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 ...
51
votes
6answers
72k 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 ...
29
votes
3answers
24k 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 ...
12
votes
3answers
281 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 ...
12
votes
4answers
7k 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 ...
9
votes
3answers
20k 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 ? ...
9
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
38k 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
7k 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
3answers
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
5answers
4k 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
4k 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 ...
5
votes
2answers
7k 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
981 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
7k 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
109 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
2answers
8k 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 ...
3
votes
7answers
855 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
3k 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
3answers
2k 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
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
2answers
1k 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
5k 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
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 ...
2
votes
1answer
662 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
3answers
301 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
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 ...
2
votes
2answers
88 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
1answer
3k 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 ...
2
votes
3answers
3k 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
13k 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
77 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
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 ...
2
votes
3answers
157 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
603 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
334 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
89 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
80 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
275 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
50 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
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?
1
vote
1answer
402 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 ...
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 ...
1
vote
3answers
2k views

Linux: how to copy a file with a certain name pattern for which the exact place in the complex directory-structure is unknown

I want to copy all files with the name XYZ* into one folder. The problem is that the files are in different subfolders and that not even the depth of the folder structure is the same for all files. ...
1
vote
2answers
368 views

Get all files from a directory without read permissions?

In Linux/Unix, if I am inside a directory of another user, but cannot view the contents of the directory by typing "ls," how do I get a copy of all the files? Is the only way to guess what the file ...
1
vote
3answers
87 views

How do you distinguish a directory, and it's contents in linux?

Let's say you have this directory tree parent -----child1 -----file0 -----grandchild1 -----file1 -----file2 ...
1
vote
1answer
198 views

Linux: Copy files with dates in filename between two dates

I have a folder full of files where I from time to time need to copy a subset of these to somewhere else for processing. The files have the date they were created in the filename, i.e. ...