Titouan Mathis

Developer & CTO at Studio Meta

Batch rename files with zmv in ZSH

20/06/2022 in #ZSH #scripts #terminal

I just (re)discovered the zmv utility from ZSH which simplify renaming things from the command line:

zmv '(*).log' '$1.txt'

It is not enabled by default, at least for me, so you might need to add the following line in your ~/.zshrc file to be able to use it:

autoload -U zmv

It also has some flags for some advanced usages:

# Dry run
zmv -n '(*).log' '$1.txt'

# Interactive mode
zmv -i '(*).log' '$1.txt'

# Verbose mode
zmv -v '(*).log' '$1.txt'