… is an easy to use and powerful tool, it can be used to replace part of file name (string1) with some other string. Something one can also do with some “sed” hack, but this tool is much easier to use, especially for beginners.
You can get all information needed from “rename –help” (here from Linux Mint):
rename --help Usage: rename [ -h|-m|-V ] [ -v ] [ -n ] [ -f ] [ -e|-E perlexpr]*|perlexpr [ files ] Options: -v, -verbose Verbose: print names of files successfully renamed. -n, -nono No action: print names of files to be renamed, but don't rename. -f, -force Over write: allow existing files to be over-written. -h, -help Help: print SYNOPSIS and OPTIONS. -m, -man Manual: print manual page. -V, -version Version: show version number. -e Expression: code to act on files name. May be repeated to build up code (like "perl -e"). If no -e, the first argument is used as code. -E Statement: code to act on files name, as -e but terminated by ';'.
I did use this tool rename some files that contained the string “www”, which I had to replace with “web”, lets say there were files named like this:
For Ubuntu, maybe also Debian, based systems I use the following command to rename all above files:
rename -e 's/www/web/' *.ccd
After this the files are now called
The only problem is, the syntax varies from one Linux distribution to another, so check the syntax before you use rename.
For Arch Linux I found that something like this would work:
rename www web *.ccd
The expression “*.ccd” defines which files to act on, so this will act on all files that match “*.ccd*, in the example above you could also use “www.example.com-*.ccd” or something similar.
Main thing I wanted to get out there is, there is an easy tool to batch rename files instead of some complex if-for bash code. Which I tried to use before but failed at.