to load zmv :

autoload -U zmv

zmv is a module that allow people to do massive rename. The first option to know about zmv is the -n option that will show what will be done without being executed.

to rename a class music files which names are la like this : artist - album - track - title.ogg :

zmv '(*) - (*) - (*) - (*).ogg' '$1/$1 - $2/$1 - $2 - $3 - $3.ogg'

the "artist/artist - album/" repository should already exist the file will keep the same name and be moved to that repository.

to recursively do the same

zmv '(**/)(*) - (*) - (*) - (*).ogg' '$1/$2/$2 - $3/$2 - $3 - $4 - $5.ogg'

Of course we can use globbing. For example, rename all the avi files to replace _ by simple spaces, replace '.' by simple spaces lowercase the filename, and capitalise the first letter of each words :

zmv '(*).avi' '${${(LC)1//./ }//_/ }.avi'

If you want case insensitivity pattern matching you can add (#i) at the begining of the first sentence for exemple

zmv '(#i)(*).avi' '${${(LC)1//./ }//_/ }.avi'

All files having for extenstions .avi or .Avi or .AVI or etc. will match and will be renamed as previously.

This is what I use to rename my photos:

c=1 base='disneyland' zmv '*.JPG' '${base}_${(l:3::0:)$((c++))}.jpg'

this renames any sequence of .JPG in disneyland_001.jpg…; that is: it both renumber starting from 1, and pad it to be 3-digits wide.

You can find more information here :

builtin/functions/zmv.txt · Last modified: 2015/12/08 07:42 by spamkiller