View Full Version : Bash to move files from a list of files

May 14th, 2010, 05:35 PM
Can any one kindly sort me out here. I have a text file containing file paths/names, one per line, and I want to move these files from one directory to another. My bash scripting syntax is terrible. Can anyone give me a one-liner or script?

May 14th, 2010, 05:44 PM
The following should do what you want:

while read file ; do cp "$file" /destination/directory ; done < list.txt

The file list.txt contains the listing of the files to be moved. I used cp rather than mv as a precaution.

May 14th, 2010, 06:21 PM
cat file |awk '{print "cp "$1" /destiniation"}'|sh

May 16th, 2010, 06:59 PM
Very grateful, Kaibob and IPoneverything.

May 16th, 2010, 08:48 PM
Looks like classic backtick use to me:

mv `cat myfile` mydestination/.

It is not safe against filenames with special characters (shell special, e.g. spaces). To be safe you'd need something like this"

cat myfile | while read foo ; do
mv "$foo" mydestination/.

Useless use of cat left in for clarity.