Farther in ZSH : ZMV

Ordinary people like their desktop environment but as a beard holder, i prefer a plain old dark terminal.

You probably know the mv command which lets you move a file. Most of the time it's ok, but sometime you may have a lot of files to rename with some common parts. And now starts hell.

You'll be able to bulk rename many files with some fancy options thanks to our beloved ZMV !

Here is a classic example where you want to rename a prefixed file :

Original Renamed
XXX-file1.jpg YYY-file1.jpg
XXX-file2.jpg YYY-file2.jpg
XXX-file3.jpg YYY-file3.jpg

zmv 'XXX(\*)' 'YYY$1'


As easy as ABC.

zmv 'the_pattern_to_remove(*)' '$1-the_new_pattern'

To be safe, you should first use -n which won't do anything except showing you the potential result. There is also an interactive mode with -i where you need to acknowledge any edit.

Of course there are other options documented but these two are the most needed.

The extra-bonus comes from the globbing and modifiers support from ZSH but i won't explain it now. With these two features, it's possible to add criterias. ex : zmv ' ' '$f:gs/ /_' will replace spaces by underscores. I admit i can't recall this one but now I know i'll find it here each time i need it.

PS : To be able to use zmv you need to add autoload -U zmv in your ~/.zshrc.