2
1
I have run a command which finds a lot of files based on some search criteria. It returns the files like so:
./somepath/somepath/file.something
./asdf/asdf/s.php
./etc/a.php
./a/b/c/d/e/f/g.jpg
So I was wondering, if I capture this output into a file (ie. one file per line), can anyone help me write a command which iterates through the file and moves the files one by one to a specified directory?
Thank you in advance.
The basic approach is sound, but your original version was missing several protections against “unusual” filenames. Always use
read -r
, as plainread
expands some backslashes. Always use double quotes around variable substitutions unless you know why not to; without the quotes, the shell would expand whitespace and\[?*
in file names. Finally,--
before the file names on themv
command line protects a file name beginning with a-
from being considered an option by themv
command. – Gilles 'SO- stop being evil' – 2010-11-02T23:28:20.803You are absolutely correct. Dashed it off without proper care--thanks for the correction. – CarlF – 2010-11-03T12:35:47.340
Thanks! I also gave it a try myself and ended up with a 30 line php script. – mqchen – 2010-11-06T11:46:41.027