Last Updated: February 21, 2019
·
29.61K
· jan0sch

Mass renaming files with zmv (zsh)

The zsh contains a very usefull extension called zmv. You can load it via autoload -U zmv. The man page is located under zshcontrib. A very usefull flag is -n which does not execute the command but prints the command that would be executed. Use this if you are unsure about your patterns.

Here are two simple examples:

Replace all spaces in filenames with underscores.

zmv '* *' '$f:gs/ /_'

Rename all files according to a pattern.

zmv '*.(*).(*).([0-9][0-9])*.mkv' '$1_$2-$3.mkv'

This one renames all files matching Garbage.Important.Important.Two-Digits-Followed-by-Garbage.mkv into Important_Important-Two-Digits.mkv.