Wednesday, 30 January 2013

Copy and rename multiple files

What do you do on Linux when you want to rename, copy or move many files together in the same way, e.g. replacing all files named "donkey01.jpg" as "horse01.jpg" ? There is plenty of GUI utilities, but sometimes a quick and cheap shell hack is needed. Here you go: the magics of sed and shell scripting in a one liner.

for i in `ls *`; do cp $i `echo $i | sed "s/search/replace/g"`; done

From here.

No comments: