Scripting names from a file

Patrick McSwiggen Pat.McSwiggen at uc.edu
Tue Sep 28 17:59:37 UTC 2004


On Sep 28, 2004, at 1:22 PM, Jeff Vian wrote:
> for i in `cat file_with_names` ; do
> mv $i /dest/dir
> done
>
> should do the trick for all files listed in the file.
> You may wish to add a -f (force) option to the move command to avoid
> nasty notes if the file does not exist or if it cannot be moved for 
> some
> reason.

If the file names have any problem characters (e.g. spaces or anything 
else that needs to be escaped from the shell) you could also use the 
following syntax:

cat file_with_names | while read line ; do
mv "$line" /dest/dir
done

This would assume the file names were listed one per line.

-- 
Patrick D. McSwiggen                         pat.mcswiggen at math.uc.edu
Department of Mathematics                     Office: +1 513 556-4080
University of Cincinnati                         FAX: +1 513 556-3417




More information about the fedora-list mailing list