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?
This will just do the trick for you:
cat file_list.txt | xargs -I {} cp {} /destination/dir/path
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With