Tagged Questions

cp - Command-line tool to copy a file

learn more… | top users | synonyms

2
votes
1answer
445 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 ...
19
votes
7answers
21k 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
8k 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
327 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
216 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
271 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 ...
32
votes
5answers
23k 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
330 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
159 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
233 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
94 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
467 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
187 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
847 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
1k 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
545 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
247 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
418 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
10k 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
3answers
644 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 ...
12
votes
3answers
3k 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
478 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
645 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
98 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
228 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 ...
23
votes
3answers
11k 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
149 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
4k 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
4k 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
860 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
7k 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 ...
6
votes
3answers
13k 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 ...
52
votes
6answers
93k 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
91 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
657 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 ...
4
votes
4answers
5k views

copying multiple files to multiple directories

I've a problem copying many files in different directories. Let me explain better: Let's say I have the following in a dir: $ ls file1 file2 file3 file4 file5 dir1 dir2 dir3 and I want to copy ...
1
vote
1answer
265 views

Switching source and destination (or undoing the mv, cp operation)

mv or cp commands both expect source and destination as arguments. In case you want to undo the change you made, or just change the source and destination you supplied before, what is the quickest ...
4
votes
2answers
4k views

issue with find -exec cp

Consider this example (newbie alert): touch test0 touch timestamp touch test1 sudo find /var/www/import -iname 'test*' -newer timestamp -exec cp {} new \; It actually copies file test1, but it ...
1
vote
2answers
136 views

How to copy a file and move it to a location using unix

I need a file to stay in the same location but also move it to a different location. What am I doing wrong? cp RubyTest.sublime-settings \ ~/Library/Application Support/Sublime\ Text\ ...
1
vote
1answer
230 views

What happens if a cron script tries to copy a directory at the same time as another process is writing to it?

For example, if I have a java process that (once every 2 hours) takes a backup of a large file, like 500mb, and places it into folder A on HDD A, and I want to schedule a cron script to copy the ...
2
votes
2answers
132 views

debian dead when copy over 1GB

I have a Debian Squeeze system with an AMD64 processor. When I try copy over 1 GB, the computer dies (no reboot, completely down), and the logs don't contain anything useful. The temperature of the ...