Monday, September 26, 2011

Oneliner for renaming files

Say you have a series of files you want to rename like so:

 a37.zip to a37-archive.zip
b38.zip to b38-archive.zip
c39.zip to c39-archive.zip

and so on...

Here's a useful oneliner for bash:

for x in `ls`; do echo $x | sed -e 's/\(.*\).zip/\1-archive.zip/g'| xargs -t mv $x ; done

That should to it. Of course, there are other ways of doing it, but this way is fairly simple.