PDA

View Full Version : [ubuntu] Pick out files from a folder



rkakkar
January 1st, 2011, 05:36 PM
i have a text file full of filenames. I want to pull out those files from a folder containing those plus a whole lotta other files, and put it in another folder. How can I do so?

TeoBigusGeekus
January 1st, 2011, 05:51 PM
Something like

#!/bin/bash
for i in $(cat /path/to/list/with/filenames/list
do
mv $i /path/to/new/location/
done

sisco311
January 1st, 2011, 06:09 PM
Something like

#!/bin/bash
for i in $(cat /path/to/list/with/filenames/list
do
mv $i /path/to/new/location/
done

This will fail if the files have spaces in their name or their name begins with a -

Try:


cd path/to/dir/with/files
while read file; do
mv -b -- "$file" path/to/new/location/
done < path/to/list/with/filenames/list

TeoBigusGeekus
January 1st, 2011, 06:19 PM
This will fail if the files have spaces in their name or their name begins with a -


^ This...