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.

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

0 Comments

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…

Squarespace Image Export

To gain continued access to your Squarespace website images after cancelling your subscription you have several...

MySQL 8.x GRANT ALL STATEMENT

-- CREATE CREATE USER 'tgnrestoreuser'@'localhost' IDENTIFIED BY 'AppleSauceLoveBird2024'; GRANT ALL PRIVILEGES ON...

Exetel Opt-Out of CGNAT

If your port forwards and inbound and/or outbound site-to-site VPN's have failed when switching to Exetel due to their...