I have a list of filenames called list.txt.
I would like to copy the files in this list to a new folder.
How shou开发者_Python百科ld I go about doing this?
Thanks!
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.
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.
use a loop
while read -r line
do
cp "$line" /destination
done <"file"
loop:
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. :)
精彩评论