Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'd like to copy a group of files to destination folder. But without needing to spawn a new instance of cp for each operation.

The arg format for cp seems to be:

cp src_file1 src_file2 src_file3 dest_dir/

Assuming I have a file with source file names listed line-by-line, how can this be done?

Since I have a very large number of files, the idea from @Scott below will not work, since it will hit the maximum command line length.

I'd like to somehow pipe that file of file names to cp and let it do it's thing. xargs also can't seem to help, as it wants to tack on the expansion at the end of the command line.

Can this be done?

Thank you

share|improve this question

If filelist contains


where those are the names of files that you want to copy to the fruity directory, type

cp `cat filelist` fruity

You don’t need the / at the end.

Warning: this won’t work if any of the file names contain spaces, e.g., passion fruit.

share|improve this answer
Won't quite work.. I've clarified the question. There are many files. – nonot1 Nov 9 '12 at 18:30
As long as none of the filenames contains a space or quote character, xargs -J {} cp {} fruit < filelist should work. If there are spaces and/or quotes, you could go with eicto’s answer, or just do tr "\n" "\0" < filelist | xargs -0 -J {} cp {} fruit. – Scott Nov 10 '12 at 0:45

Simulate print0 of find :

cat filelist |perl -p -e 's/\n/\000/' |xargs -0 cp --target-directory dest_dir/

this sample includes xargs -0,--target-directory

share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .