Questions tagged [cp]

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

Filter by
Sorted by
Tagged with
20 votes
3 answers
35k 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 complete....
nelaaro's user avatar
  • 13.6k
2 votes
3 answers
466 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?
Narek's user avatar
  • 1,421
1 vote
0 answers
308 views

shortcut to recursively copying a directory preserving modes, ownerships and hard and symbolic links

I am using the following to recursively copy a directory while preserving modes, permissions as well as hard and symbolic links: cp -pr --preserve=links dir-a dir-b However I have the following ...
MarcusJuniusBrutus's user avatar
23 votes
4 answers
69k views

Copying many files without stopping on errors on OSX

I need to copy several Gb from an external HD to my main 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 matter ...
cfischer's user avatar
  • 9,063
11 votes
1 answer
18k views

Copy files from a numeric range to another folder

Slightly stumped on what CP command would copy files numbered 14 trough 39 into a directory called Volume2 from the following example: 01.mp3 04.mp3 07.mp3 10.mp3 13.mp3 16.mp3 19.mp3 22.mp3 ...
user98496's user avatar
  • 733
25 votes
4 answers
70k 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 ...
PeanutsMonkey's user avatar
2 votes
2 answers
6k views

cp --update still copies unchanged files

I'm trying to copy only changed files using 'cp -pu' under Linux (Red Hat 6.1, source/destination FS are GlusterFS mounted partitions) but I found that it still tries to copy file seemingly old and ...
teddy's user avatar
  • 121
0 votes
3 answers
248 views

cp command inquiry

If I am in a directory called /usr/share/tcl8.3/encoding, what command would copy all files begining "cp" that also contain an even number (from the following list): cp1250.enc cp1255.enc cp737.enc ...
user98496's user avatar
  • 733
5 votes
1 answer
16k views

Symlink all files in a Folder to a new Folder

Ideally what I am seeking is a way to rename all my anime keeping original files intact without using extra data space The solution I can think of is creating a duplicate folder path to another ...
MasterCATZ's user avatar
5 votes
2 answers
16k 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 ...
Jim's user avatar
  • 671
1 vote
1 answer
903 views

Using a Linux/Unix terminal to copy many files to a new location

I'm trying to use the a Linux terminal to copy many files to a new location. I tired the command: sudo locate -i file_I_want | xargs cp $1 /place_I_want_everything_copied_to/ Which, gives an error. ...
InBetween's user avatar
  • 175
1 vote
3 answers
181 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 -----...
user893730's user avatar
  • 1,217
1 vote
0 answers
91 views

Maintaining peak IO potential with DD / CP

I wanted to copy a file (40 gig dataset) from a single drive to a dual disk raid-0 drive. I tried with CP and it sustained read - 4mb and write - 11 mb (doesn't make sense I know (must be the stripe ...
Hassan Syed's user avatar
0 votes
2 answers
156 views

Different performance for different USB 2.0 devices

I copied a 3.5GB file from my SATA HD to my Seagate USB 2.0 external HD in about 3 minutes. I copied the same 3.5GB file from my SATA HD to my USB 2.0 SanDisk Cruzer and it took more than 15 minutes. ...
user985675's user avatar
0 votes
1 answer
15k views

Can't create directory, "permission denied" error

I am executing the following command from my Linux machine. cp -r hwweb-ws-5.0 /home/tomcat/hwweb-1/webapps/ It's displaying the following error: cp: cannot create directory `/home/tomcat/hwweb-1/...
user avatar
5 votes
5 answers
6k 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 ...
Phyo Arkar Lwin's user avatar
62 votes
4 answers
89k views

Copying a file only when it is newer than the destination

How do I copy a file in Linux only when the file being copied is newer than the version at the destination? If the file at the destination is newer, I want the file copy to not go ahead.
Eli's user avatar
  • 795
3 votes
3 answers
3k 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. ...
Matt V.'s user avatar
  • 165
5 votes
1 answer
9k 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 ...
Thibaut's user avatar
  • 51
7 votes
3 answers
33k 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. ...
user avatar
2 votes
1 answer
115 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 ...
Richard's user avatar
  • 995
1 vote
1 answer
214 views

Pass wildcard array to cp

I need help with passing a wild card array to cp, I know it can be done but cant figure it out, ive got 3 files all start with the word somefile but have 3 different extensions somefile.conf ...
squareborg's user avatar
  • 2,465
1 vote
1 answer
2k views

I/O error while cp from CD to HDD

I'm trying to create a local repo from my RHEL6 disk. Some of the .rpms I'm able to copy, others give me this error: cp: reading 'filename': Input/Output error It's the original RedHat disk, and it ...
Chen A.'s user avatar
  • 113
0 votes
2 answers
2k views

cp command can't find some directories

I'm trying to copy a bunch of files/directories using a terminal command, cp. The command I'm using is: sudo cp -r *.tests ~/Desktop tests are directories with stuff in them. However I get a few ...
JPC's user avatar
  • 193
2 votes
1 answer
791 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 /bar/a,b,...
Mike's user avatar
  • 23
4 votes
1 answer
2k 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 ...
Woltan's user avatar
  • 43
5 votes
1 answer
2k 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 ...
Laurent Giroud's user avatar
3 votes
3 answers
11k 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 ...
SlappyTheFish's user avatar
0 votes
4 answers
853 views

Copy the contents of a directory into another

I would like to copy the contents of a directory into another. I don't want to copy the directory and all files and directories under it, but just the contents of the directory just as if it were a ...
Juggler's user avatar
  • 1,701
1 vote
1 answer
2k views

cp -a is preserving ownership, from non-root user

When I invoke cp -a 1 2 from a non-root user, the ownership is being preserved, despite the fact that file 1 belongs to another user. My understanding was this shouldn't be possible. What is going on?...
Matt Joiner's user avatar
  • 1,074
1 vote
1 answer
267 views

Debian: rsync and cp is corrupting contents of CSV files

I have a weird problem. I wrote a script that scans a directory on a samba share (a OpenSUSE server on the LAN) and uses cp to copy certain CSV files to the local Debian server web root at /var/www. ...
George's user avatar
  • 163
97 votes
8 answers
125k 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 ...
unclaimedbaggage's user avatar
13 votes
3 answers
517 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 /home/...
Fisher's user avatar
  • 213
1 vote
1 answer
2k views

permission denied while copying files with root

Ok, how is it possible that I get perm denied when I'm copying files in console. Any ideas?
oneat's user avatar
  • 3,321
3 votes
4 answers
21k 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 ...
Jason's user avatar
  • 1,899
0 votes
4 answers
5k views

cp -ru -> using the recursive copy and update in linux from my internal drive to a mounted nas

I've mounted my NAS drive under the /media/ directory. I've copied a bunch of files from my current /var/www directory, using cp -Rpv (preserve). Now I want to do a cp -Rup /var/www/ /media/magneto/...
Jason's user avatar
  • 1,899
0 votes
1 answer
4k views

How to copy files and directories while retaining file permissions in UNIX

How can I copy files and directories from one user to another user on a unix system so that the file permissions don't change? The recipient is not the owner, but I have root permissions. Thanks.
Aniket's user avatar
  • 1
0 votes
2 answers
8k views

Copy files off FreeBSD

I have a FreeBSD machine that I have to copy everything off the drive. The fielsystem is UFS and not readable by any other operating system. (great...) I have a USB flash drive (FAT32) I need to copy ...
user avatar
5 votes
2 answers
18k views

How to copy a Read-Only file and make the copy writable with a single cp command?

How to copy a Read-Only file in Linux and make the copy writable with a single cp command in Linux (Ubuntu 10.04)? The --no-preserve and --preserve seemed to be good candidates, except that they ...
user2138912's user avatar
1 vote
2 answers
262 views

Questions about using scp

In a previous post, I asked a question about simply right-click copy and paste in Nautilus sometimes cannot handle files with special characters in their names under Ubuntu. Later I found that scp ...
Tim's user avatar
  • 17.3k
17 votes
5 answers
32k 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 ...
janesconference's user avatar
2 votes
3 answers
954 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 '{...
Matthieu Cartier's user avatar
0 votes
2 answers
3k views

rtorrent copy after download

so I`m trying to do the following: When rtorrent finishes download, it should copy files from download dir to another dir called uploads, so the file would be in Downloads dir AND in Uploads dir. ...
toms's user avatar
  • 1
1 vote
1 answer
385 views

linux cp command with rtorrent

so I`m trying to do the following: When rtorrent finishes download, it should copy files from download dir to another dir called uploads, so the file would be in Downloads dir AND in Uploads dir. ...
Treat's user avatar
  • 96
24 votes
3 answers
9k 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 the ability to ...
sligocki's user avatar
  • 878
0 votes
1 answer
1k views

cp linux command options

how i do i copy all files from dir to another dir and escape file already exist and not overwrite it , using cp command under linux centos
user avatar
1 vote
1 answer
71 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 ...
LinuxPenseur's user avatar
115 votes
4 answers
154k 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 ...
user avatar
1 vote
2 answers
3k views

Find files in subdirectories and copy them to another directory with the same subdirectories?

This question is very similar to this one except that I want to maintain the file's original subdirectories. For example if I had /temp/a/a.txt /temp/a/a.jpg /temp/a/b.txt /temp/b/c.txt /temp/d/d....
evan's user avatar
  • 363
1 vote
2 answers
537 views

argument to cp in backticks doesn't work?

I tried using a command like cp `ls ~/temp/*.xyz | head -1` ./ But that does not work. If I echo the value of command inside back ticks and put it manually in cp command it works. Any ideas?
Osada Lakmal's user avatar