Share your feedback via email, using Mastodon or
Mass renaming in Zsh
Use glob to easily rename multiple files at once
Renaming multiple files in one commandline may be challenging… until you discover that Zsh comes with a built-in feature called zmv which is unfortunately disabled by default.
So the first thing you want to do is to activate it by simply adding this line to your .zshrc:
autoload zmvThen reload Zsh and you’re done.
When you add a feature you usually expect to have to deal with a bunch of configuration as well. Good news here: there’s no additional config necessary !
The basic structure of a zmv call is zmv 'input_pattern' 'output_pattern'.
The patterns are included in single quotes and you would have to use brackets to respect the standard Z Shell syntax to match the enclosed patterns but you can make your life easier by removing the use of quotes by adding the tag -W to the zmv command, and removing the use of brackets by prepanding your command with noglob. Hence, let’s take the example of the files:
photo1-onJan01.jpg
photo2-onJan01.jpg
photo3-onJan01.jpgUsing:
noglob zmv -W photo*Jan*.jpg myphoto*Dec*.jpgWill rename all the files like that:
myphoto1-onDec01.jpg
myphoto2-onDec01.jpg
myphoto3-onDec01.jpgImagine combining your new super power with other tools like fd and you can see how efficient you can be at mass renaming files in a single commandline !
Of course, to save you time, create an alias (rn for example) for your new noglob zmv -W command.