Linux Mass Rename / copy / link Tools

There are a few different ways to perform mass renaming of files in GNU/Linux (yes, mass renaming is possible!). There is also a perl script that renames the extentions on files. Below are three ways to perform mass renaming of files, using the commands mmv, rename (a perl script) or some bash shell scripting.

 

Using MMV command

 

mmv is a mass move/copy/renaming tool that uses standard wildcards to perform its functions.mmv’s manual page is quite difficult to understand, I have only a limited understanding of this tool. However mmv supports some standard wildcards. According to the manual the “;” wildcard is useful for matching files at any depth in the directory tree (ie it will go below the current directory, recursively). An example of how to use mmv is shown below:

 

  • # mmv \*.JPG \#1.jpg

The first pattern matches anything with a “.JPG” and renames each file (the “#1” matches the first wildcard) to “.jpg”.

 

MMV home page : http://linux.maruhn.com/sec/mmv.html

 

rename command

 

Rename is a perl script which can be used to mass rename files according to a regular expression. An example for renaming all “.JPG” files to “.jpg” is:

 

  • # rename ‘s/\.JPG$/.jpg/’ *.JPG

Rename command home page : http://search.cpan.org/~pederst/rename-1.4/

 

Rename using Bash scripting

 

Bash scripting is one way to rename files. You can develop a set of instructions (a script) to rename files. Scripts are useful if you don’t have mmv or rename…

 

#!/bin/sh
for i in *.JPG;
do mv $i `basename $i JPG`jpg;
done

 

The first line says find everything with the “.JPG” extension (capitals only, because the UNIX system is case sensitive). The second line uses basename (type man basename for more details) with the ‘$i’ argument. The ‘$i’ is a string containing the name of the file that matches. The next portion of the line removes the JPG extension from the end and adds the jpg extention to each file. The command mv is run on the output. An alternative is:

 

#!/bin/sh
for i in *.JPG;
do mv $i ${i%%.JPG}.jpg;
done

 

The above script renames files using a built−in bash function.