Copy a list of files from one location to another in Linux

I am trying to copy a partial list of files on disk to a folder on another disk. The list of files to copy is in a text file that I tried to provide a bash script as well as some cp and xargs commands to no avail. Below is an attempt at bash.

#!/bin/bash

while read line
do
    find . -iname "$line" -exec cp '{}' /my/destination/drive \;
done < file_list.txt 

      

The text file is read as filenames without extensions like below

my-file001
my-file002
my-file003

      

I've also tried xargs and pax with the attempts below, 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?

+3


source to share


1 answer


It just helps you:



 cat file_list.txt | xargs -I {} cp {} /destination/dir/path

      

+7


source







All Articles