mmv — move multiple files by wildcard patterns 
Introduction
If you ever have to rename or move multiple files under Linux, then the mmv shell command will make your life easy. The mmv utility will also come in handy for copying multiple files, appending content of one file to other files, as well as for creation of links.
Installation
While mmv is typically not included as part of base build for Linux distros, it should be included on the installation media. If not, then you will have to use your favourite package manager (yum, yast, apt, smart, etc.) to install it from the web.
Synopsis
A brief synopsis of the mmv command, including the most commonly used switches and parameters, is given below:
mmv [-m|r|c|o|a|l|s] [-h] [-v|n] [from to]
-m : move source file to target name
-r : rename source file or directory to target name
-c : copy source file to target name
-o : overwrite target name with source file
-a : append contents of source file to target name
-l : link target name to source file
-s : same as -l, but use symbolic links instead of hard links
-v : verbose mode
-n : no-execute mode
-h : help information
*see the man pages for full description of available switches
Example usage
You can run the following examples from any Linux shell, I will use bash. Lets start with some simple examples. To change extensions of all files in the current directory from .jpeg to .jpg, use:
mmv "*.jpeg" "#1.jpg"
Notice, how in the above example, the match for a * wildcard in the first argument (source/from pattern) gets used in the second argument (destination/to pattern) via #1.
Similarly, if we have more than one wildcard, the match for the second wildcard can be used in the destination pattern with #2, and so on. For example, the following command will insert an underscore after the first occurrence of the word page in filenames with extensions starting with htm:
mmv "*page*.htm*" "#1page_#2.htm#3"
It is also possible to include entire path-names with from/to wildcard patterns:
mmv "./foo_*/bar/*.txt" "./foo_#1/#2.txt"
In the above example, all .txt files contained in bar sub-directory of any foo_* parent directory, are moved one level up, i.e. into their corresponding foo_* directories.
You can run recursion on files in sub-directories, like so:
mmv -r "foo*/*.txt" "~#2.txt"
mmv also allows for case conversion. For example, to lowercase all of the files in the current directory, use:
mmv "*" "#l1"
To upercase all the files and directories in the current directory, include the -r switch:
mmv -r "*" "#u1"
To append contents of all .txt files in the present directory to an output all.txt file, use:
mmv -a "*.txt" "all.txt"
With verbose mode enabled (-v switch), the above command displays the following information:
mmv -v -a "file?.txt" "all.txt"
file1.txt -> all.txt : done
file2.txt -> all.txt : done
file3.txt -> all.txt : done
For further details consult the man pages:
man mmv
Other tools
There are also other ways of performing multiple file operations. These might be useful if, for whatever reason, mmv is unavailable.
To change extensions from .abc to .123, use one of the following:
for i in *.abc; do mv "$i" "${i/\.abc/.123}"; done
for i in *.abc; do mv $i `echo $i|sed 's/\.abc$/.123$/'`; done
for i in *; do mv $i `basename $i .abc`.123; done
The following bash one-liners convert filenames to lowercase:
for f in `find *`; do mv "$f" "`echo "$f" | tr A-Z a-z`"; done for f in `find . -type f -name "*[A-Z]*"`; do mv "$f" "`echo "$f" | tr A-Z a-z`"; done
Did you find the above information useful and interesting? If so, please support this site by using the blog directory links at the bottom of this page. Thanks for your support!
If you have any Linux related problems or questions then please feel free to post them on our Linux Forums: http://linux.dsplabs.com.au/forums.

February 25th, 2008 at 5:26 pm
for i in *.abc; do mv $i `echo $i|sed 's/.abc$/.123$/'`; done
can be done in bash with:
for i in *.abc; do mv "$i" "${i/.abc/.123}"; done
If you omit the " (as you do in your expression) you will not treat filenames with spaces correctly, furthermore the regex is incorrect . is a wildcard in your expression - it should be escaped vie \.
Cheers,
Konrad
February 25th, 2008 at 5:55 pm
Hi Konrad,
Thank you for your comment with useful information. I have made the suggested changes.
Cheers,
Kamil
February 7th, 2010 at 11:50 am
[…] can get it from any other repo I have had a hard time finding just a source package for it though. Linux Blog mmv — move multiple files by wildcard patterns […]
November 16th, 2010 at 2:20 am
try also:
rename 's/.abc$/.123$/' *.abc
April 13th, 2011 at 3:48 pm
Thank you! Your bash 1 liner does the trick as I dont have mmv in cygwin by default. Woot!
November 4th, 2011 at 11:31 am
ge spacemaker microwave…
[…]Linux Blog » mmv — move multiple files by wildcard patterns[…]…
November 6th, 2011 at 2:52 am
Crawl Space Guru…
[…]Linux Blog » mmv — move multiple files by wildcard patterns[…]…