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]
myuser@mypc:~$ mkdir rename_test
myuser@mypc:~$ cd rename_test/
# create some test files
myuser@mypc:~/rename_test$ touch file1.txt
myuser@mypc:~/rename_test$ touch file2.txt
myuser@mypc:~/rename_test$ touch file3.pdf
myuser@mypc:~/rename_test$ touch file4.ogg
myuser@mypc:~/rename_test$ ls
file1.txt  file2.txt  file3.pdf  file4.ogg
myuser@mypc:~/rename_test$ ren
rename     rename.ul  renice
myuser@mypc:~/rename_test$ rename
Usage: rename [-v] [-n] [-f] perlexpr [filenames]
myuser@mypc:~/rename_test$ rename 's/file/new_prefix/g' *
myuser@mypc:~/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. Required fields are marked *

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

The reCAPTCHA verification period has expired. Please reload the page.

You May Also Like…

Network speed test host to host

On Ubuntu / Debian apt-get install iperf3 On Windows download it from Make...

Clear HSTS Settings in CHrome

Open chrome://net-internals/#hsts enter the domain in the query field and click Query to confirm it has HSTS settings...