Reputation: 101
I'm attempting to copy a partial list of files on a drive to a location on another drive. The list of files to copy is in a text file that I've attempted to supply to a bash script as well as some cp and xargs commands but to no avail. Below is the bash attempt.
#!/bin/bash
while read line
do
find . -iname "$line" -exec cp '{}' /my/destination/drive \;
done < file_list.txt
The text file reads as filenames with no extensions, like below
my-file001
my-file002
my-file003
I've also tried xargs and pax with the below attempts, also to no avail.
cat file_list.txt | xargs cp -t /my/destination/drive
and
find . -type f -exec pax -rws'|.*/||' < file_list.txt /my/destination/drive/ '{}' \;
This question came close but not quite. Any suggestions?
Upvotes: 6
Views: 13497
Reputation: 2382
This will just do the trick for you:
cat file_list.txt | xargs -I {} cp {} /destination/dir/path
Upvotes: 11