Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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
add comment

2 Answers

If filelist contains

apple
orange
banana

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
add comment

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
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.