cyberpirate92
cyberpirate92

Reputation: 3186

How to copy files to a particular folder where i have the filenames inside a file?

I am using linux, I have a file containing nearly 90 filenames of files from various locations in my HDD. I want to copy those files to a USB drive, how could i do that? The file containing filenames is in the following format :

file1
file2 
. 
. 
.
filen

I think a shell script could do that easily , but since i'm a beginner I don't know how to write it. Please provide a solution.

Upvotes: 0

Views: 176

Answers (1)

Kevin Seifert
Kevin Seifert

Reputation: 3582

You have to know the path to the usb drive. Then the copy command looks like

cp somefile tolocation

you'd need to put this in a loop that read the file

while read line
do
    echo $line;
    echo "do your copy here, for example cp $line /tmp/"
done < "yourfile"

Upvotes: 2

Related Questions