Re: Bulk moving of files



Owen wrote:
I just polluted a directory with 100 odd files, they were meant to go
into a sub directory. All files have a date so that ls -l|grep
'2010-03-23' list the files that need moving.

What one liner can I use to move them all into the sub directory in
one operation?

Hello Owen,

you've already got some good answers on this one, but here's something I
find myself doing quite often: an ls | sed | sh pipe. Recently I had to
convert a bunch of files that had dates of the form DD.MM.YYYY in their
(otherwise quite random) names to easily sortable names like
file_YYYY-MM-DD.txt.

This is what I did: ls | sed -nr
's/.*([0-9]{2})\.([0-9]{2})\.([0-9]{4}).*/mv -i "\0"
file_\3-\2-\1.txt/p' | sh

(typed from memory, there might be syntax issues).

I also like to generate shell scripts using find's -printf directive.
Actually, find, sed and sh make an extremely powerful batch file
operation team.

robert
.


Quantcast