Blame it on the rename (renaming multiple files using a regular expression)

Written by James McDonald

September 24, 2013

Just discovered the rename utility under Linux

Warning: There appears to be two ‘rename’ utilities one under Debian 6.0.7 works as below and is a Perl utility. The other, which I found on Fedora 19 is part of util-linux, and doesn’t work the same way (i.e. it’s a lot dumber).

Work-a-round copy /usr/bin/prename from your Debian system to /usr/bin on your Fedora System and run prename instead of rename.

Usage: rename [-v] [-n] [-f] perlexpr [filenames]
[email protected]:~$ mkdir rename_test
[email protected]:~$ cd rename_test/
# create some test files
[email protected]:~/rename_test$ touch file1.txt
[email protected]:~/rename_test$ touch file2.txt
[email protected]:~/rename_test$ touch file3.pdf
[email protected]:~/rename_test$ touch file4.ogg
[email protected]:~/rename_test$ ls
file1.txt  file2.txt  file3.pdf  file4.ogg
[email protected]:~/rename_test$ ren
rename     rename.ul  renice
[email protected]:~/rename_test$ rename
Usage: rename [-v] [-n] [-f] perlexpr [filenames]
[email protected]:~/rename_test$ rename 's/file/new_prefix/g' *
[email protected]:~/rename_test$ ls
new_prefix1.txt  new_prefix2.txt  new_prefix3.pdf  new_prefix4.ogg


Submit a Comment

Your email address will not be published.

You May Also Like…


Zebra Printer Language The above website has a page where you can enter ZPL and it...

PHP Iterators

Just came across a Youtube talk "Iterators in PHP" by Jake Smith published in 2014 that steps through the many...

PHP array_map Multiple Arrays

array_map can take multiple arrays. I like how it starts mapping through them starting at the first element of each...