cp - Command-line tool to copy a file

learn more… | top users | synonyms

3
votes
1answer
4k views

Unzip file contents, but without creating archive folder

I have a file myarchive.zip that contains many directories, files, etc. Let's say this myarchive.zip file lives in a directory called "b". Well, when I use the "unzip myarchive.zip" command, the ...
1
vote
3answers
400 views

Why does this work: “cp image.bin /dev/mapper/loop0p1”?

Why does this work? cp image.bin /dev/mapper/loop0p1 image.bin is a partition image. I have tried it and works, but why? Shouldn't a dd be used?
4
votes
3answers
3k views

`cp -al` snapshot whose hard links get directed to a new file when edited

I am trying to take snapshots of a massive folder regularly. I have read here: http://www.mikerubel.org/computers/rsync_snapshots/#Incremental that cp -al takes a snapshot of a folder by simply ...
2
votes
1answer
955 views

Copying a working Linux instead of installing a new one [duplicate]

It is possible to move an installed Linux from one drive to another or from one disk to another by two methods: dd command which copies sector by sector including boot sector cp command, and then ...
1
vote
1answer
62 views

How rename directories tree entry by entry

I have text file contain two columns: current directory name the new name of the last entry d_7154/d_7161/ 'Main Integration' ...
2
votes
2answers
725 views

Can one copy a relpath in one command?

I find myself doing this often enough that I wonder if there's a standard Unix way to do it: % mkdir -p /TARGETDIR/relative/path/to % cp ./relative/path/to/somefile /TARGETDIR/relative/path/to In ...
2
votes
1answer
641 views

Minimal command to make a copy of a file [duplicate]

I often find myself copy-pasting long path in order to create a copy of a file cp /path/to/file/file1 /path/to/file/file1.bkp Is there an alternative utility that will NOT require me to type the ...
22
votes
8answers
24k views

How to check progress of running cp?

Is it possible to check the progress of running cp process? Some processes respond to various KILL signals so that you can check what is their status. I know that I can run cp with parameter -v but ...
1
vote
2answers
9k views

faster alternative to cp -a

For a simple transfer of /home to another disk i use cp -a that seems to me an extremely slow way. Should like know a more efficient way to complete the task. I have /home mounted as logical volume, ...
8
votes
2answers
335 views

Why do `cp` and `rm` treat directories separately?

Why do tools like cp and rm treat directories separately from regular files? They both require the user to explicitly specify she wants a recursive behavior, or else they won't deal with directories ...
2
votes
1answer
227 views

What happens when I copy a file from one network location to another

Suppose I have three networked computers: A, B and C. A mounts a directory from B and from C. A/mnt/im-on-B/ A/mnt/im-on-C/ A then copies a file: cp /mnt/im-on-B/file ../im-on-C/ What happens ...
2
votes
3answers
302 views

How to copy a list of files and adjust destination filenames on the fly?

When I don't need to adjust destination filenames I can do something like this: $ find -type f -name '*.pat' -print0 | xargs -O cp -t /path/to/dest It is safe because the filenames may even ...
38
votes
6answers
29k views

Is it possible to see cp speed and % copied?

I'm having problems when copy large files using nautilus (it gets stuck) so I need to copy using cp. I would like to know if there is any parameter that shows the % copied and also the transfer ...
1
vote
1answer
342 views

Killed `rm` and `cp` on nfs share

I am just testing an rsnapshot installation on my laptop which should backup to a NAS mounted via nfs on my laptop. On one test rsnapshot died with a cp -al problem (i.e. a problem with hard links) ...
1
vote
2answers
165 views

Shell : Сopy one directory to multiple directories

There is a directory YYY and a structure on the site: site1.ru/wp-content/plugins/ site2.ru/wp-content/plugins/ ... site10.ru/wp-content/plugins/ Task: YYY directory to copy all directories plugins ...
2
votes
3answers
253 views

How to cp or rm files based on ownership / permission

After a problem with spam, I stopped postfix postfix stop and checked through the mailq manually to find hundreds of thousands of unsent spam. The spam was sent from one of the sites hosted ...
7
votes
1answer
98 views

Is there a way to express: `--link` or fall back to ordinary copy in cp (from GNU coreutils)?

Is there a way to tell cp to --link (i.e. create hard links), but fall back in the case where I am attempting inter-device hardlinks? Inter-device links aren't possible and would cause cp to fail. ...
2
votes
3answers
504 views

Use find + sed + cp to find files and copy them to a directory with a different name

I'm trying to copy a bunch of files named folder.jpg into a folder. The problem is because all the files are named the same thing, I need to rename them in the process. I know I can probably do it ...
2
votes
1answer
210 views

How can I copy a git repo from a Makefile?

I'm writing a Makefile to sync my local dotfiles with GitHub. I recently decided to also add my .vim folder to the repo. But when trying to copy the .vim folder I keep getting a Permission denied ...
0
votes
0answers
46 views

Move files replacing? [duplicate]

Possible Duplicate: ‘mv’ equivalent of drag and drop with replace? I'd like to take a folder /a/b/c, and copy all files in /a/b/x into /a/b/c, replacing all files in /a/b/c with the ones in ...
1
vote
1answer
889 views

How to copy symbolic links while preserving the validity of the link?

Say under directory /usr/local/boost_1_52_0/stage/lib, I have a symbolic link: libboost_timer.so, which points to the regular file libboost_timer.so.1.52.0 in the same directory. How can I cp the ...
6
votes
2answers
5k views

tar files from another directory without copying them

This should be very simple for experts in here. I have a Linux account with user disk quota of only 6GB. There is some data-folder in /opt with about 3GB of data with when compressed comes up 1GB. ...
9
votes
6answers
2k views

How to copy every 4th file in a folder

I have a lot of files in a folder, named like 00802_Bla_Aquarium_XXXXX.jpg. Now I need to copy every 4th file to a subfolder, saying in selected/. 00802_Bla_Aquarium_00020.jpg <= this one ...
1
vote
2answers
606 views

Copying only differences?

I want to recursively copy one directory over another, however I only want to copy differences. The reason is that I'm doing this on Solaris on a volume which is snapshot, i.e. if I'm copying 100gig ...
4
votes
2answers
256 views

Copy files with deleting suffix in name

How can be done coping files that have some suffix at the end, into same dir with the smallest command possible: Example have directory containing files: cassandra.yml.example database.yml.example ...
0
votes
1answer
446 views

Unix cp wildcard with directory structure [duplicate]

Possible Duplicate: How can I copy a subset of files from a directory while preserving the folder structure? I have a bunch of directories like this: /Artists/Example Name ...
1
vote
2answers
1k views

How to avoid cp -r ~/some/folder/ . copying all files to the current folder's top level?

(Update: this happens on Mac OS X -- I am using Mountain Lion.) It sometimes happen that I use the tab key to complete the path, so my command may be: cp -r ~/some/folder/ . but it turns out that ...
6
votes
2answers
11k views

How do I copy a symbolic link?

I have a symbolic link to a file in one directory. I would like to have that same link in another directory. How do I copy a symbolic link? I tried to cp the symbolic link but this copies the file ...
9
votes
4answers
3k views

pv for directory copy

I need to copy a very large directory (talking in terabytes here) and want to monitor the progress. I found that pv is a nice utility, but how can I use it for copying directories recursively? (pv ...
4
votes
4answers
2k views

Make cp return an error value if the target exists

Is there a way to make cp (from GNU coreutils on Linux) return a nonzero value in case the target file does already exist? Or is there any other small utility which is commonly available and which ...
3
votes
2answers
683 views

Copy multiple files to one dir with parallel

I'm using the following script to copy multiple files into one folder: { echo $BASE1; echo $BASE2; echo $BASE3; } | parallel cp -a {} $DEST Is there any way to use only one echo $BASE with brace ...
14
votes
3answers
4k views

Flattening a nested directory

This is probably very simple, but I can't figure it out. I have a directory structure like this (dir2 is inside dir1): /dir1 /dir2 | --- file1 | --- file2 What is ...
1
vote
3answers
1k views

Copy files with permission 200

I want to recursively copy a directory, preserving file attributes, which contains a directory tree including some files that have permission 200 (i.e. --w-------). The copy command cp -ar ...
10
votes
3answers
3k views

How does “cp” handle open files?

I'm having two separate directories. The user loads a file into the first. Theres a cronjob running in the background which copies the files every 5 minutes over to the second directory. What happens ...
5
votes
1answer
521 views

Symbolic links with ls, mv: forcing the functions to utilize “logical” addresses (remembering the original path)

It seems that for many basic functions operating on symbolic links, the physical path is used by default. However, cd works fine. When moving into a symbolic link, cd remembers where I came from so it ...
11
votes
4answers
5k views

Copying a single file to multiple directories using cp

This question is a sequel of sorts to my earlier question, Creating numerous directories using mkdir. I am using the bash shell. I have created fifty directories, each starting with the prefix "s", ...
2
votes
2answers
660 views

How to copy a piped list of files contained spaces and apostrophes?

I have a list of files generated using find that I want to feed (pipe) to cp. My problem is that the files have spaces and apostrophes in them, leading cp to repeatedly complain that it "cannot stat". ...
1
vote
1answer
102 views

Will files created under source directory after running `cp` be copied?

Suppose I use cp to copy a directory to another place. If the process takes long, and I create a new file under the source directory, will it be copied, or does it depend on something?
2
votes
2answers
242 views

cp file device:directory on Minix

In my operating systems class we had to modify the boot screen of the Minix OS. I understood just about everything we did, but at the end of the make for compiling the new OS, there's a line: cp ...
27
votes
3answers
12k views

Why unix mv program doesn't need -R (recursive) option for directories but cp does need it?

This is a kind of "wtf?" question, so I'm sorry if I will disturb someone's vision of how things should be or if I will just annoy you with the "stupid" question. I always get messed up when need to ...
2
votes
2answers
3k views

Create symbolic links with wildcards

I have multiple hard drives with the same directory hierarchy, for example: /media/sda/dir1 /media/sda/dir2 ... /media/sdb/dir1 /media/sdb/dir2 Two hard drives with similar names and similar ...
1
vote
1answer
152 views

Move some files on every dir to a different dir [duplicate]

Possible Duplicate: How can I move files by type recursively from a directory and its sub-directories to another directory? I'm quite new to Linux and specially to the shell and all of its ...
4
votes
2answers
5k views

Difference between cp -r and cp -a

Looking for the difference between cp -r and cp -a? What does recursive mean in terms of copying files from a folder?
7
votes
4answers
5k views

cp or rsync, is cp really worth it?

I hope this does not count as a question without a real answer, as I can't seem to find a good reason to use cp(1) over rsync(1) in virtually all circumstances. Should one typically favour rsync over ...
3
votes
6answers
880 views

Make directory copies using find

I have a directory with a bunch of subdirectories in it. Thus /usr/local/src/ccl/ccl-1.8/x86-headers$ ls elf gl gmp gnome2 gtk2 jni libc Each of these directories has a further subdirectory C ...
7
votes
5answers
8k views

How to copy directories with preserving hardlinks?

How to move directories that have files in common from one to another partition ? Let's assume we have partition mounted on /mnt/X with directories sharing files with hardlinks. How to move such ...
7
votes
3answers
14k views

Using rsync to move (not copy) files between directories?

I have been using rsync to copy files for some time. My understanding is that rsync is faster than cp when some of the files to transfer are already in the destination directory, transferring only the ...
56
votes
6answers
104k views

How do I copy a folder keeping owners and permissions intact?

So I was going to back up my home folder by copying it to an external drive as follows: sudo cp -r /home/my_home /media/backup/my_home With the result that all folders on the external drives are ...
3
votes
3answers
92 views

What are some quick ways of making N copies of a particular file?

Say, if I wanted to make N copies of a.txt, and wanted them to be numbered a1.txt, a2.txt, a3.txt, etc... How would I do such a thing succinctly?
5
votes
3answers
677 views

Batch copy to multiple directories

I have about 9000 files in a directory and I want to mv them into 90 files in 100 directories by filename order, ignoring any remainder. In Copy multiple files from filename X to filename Y?, Caleb ...