Friday, September 19, 2008

Bash rename command - rename multiple files

Bash rename command is very useful to rename files in bulk.


$ ls
a.cpp b.cpp c.cpp d.cpp

Now to rename all the *.cpp to *.cpp.bak using rename

$ rename 's/\.cpp$/.cpp.bak/' *.cpp

$ ls
a.cpp.bak b.cpp.bak c.cpp.bak d.cpp.bak

Now to rename all files matching "*.bak" to strip the extension,

$ rename 's/\.bak$//' *.bak

$ ls
a.cpp b.cpp c.cpp d.cpp

1 comment:

Anonymous said...

Its not bash command but rather a Perl script.

© Jadu Saikia