I have a list of filenames called list.txt.
I would like to copy the files in this list to a new folder.
How should I go about doing this?
You can do this:
cp `cat list.txt` new-folder/
Note that you should avoid having spaces in your filenames when using this (another solution would be needed if this is the case).
The backticks execute the
cat list.txt command and use the output of that command as part of the command line to
cp. Newlines in the output of
cat are collapsed to spaces before command line substitution.
use a loop
while read -r line do cp "$line" /destination done <"file"
If you want to preserve directory structure, use one of these (assuming GNU tar):
cpio -pvdm /destination <list.txt tar -cf - -F list.txt | tar -C /destination -x
In both cases, the net result is that /destination is prefixed to the names of the files in list.txt.
dest="<destination folder>" #keep the quotes for i in `cat < list.txt` #loop each line of list.txt do cp $i $dest #in each loop copy $i, e/a line of list.txt to $dest echo "Done." done
Tested. Make sure "./list.txt" exists, otherwise manually fill in the absolute path. :)