Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Copy list of files from one location to another in linux

Tags:

linux

bash

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?

like image 597
Jake Avatar asked Oct 16 '14 04:10

Jake


1 Answers

This will just do the trick for you:

 cat file_list.txt | xargs -I {} cp {} /destination/dir/path
like image 125
iqstatic Avatar answered Oct 15 '22 13:10

iqstatic