---
date: 2022-06-20
title: Batch rename files with zmv in ZSH
description: Use the `zmv` utility from ZSH to easily rename multiple files.
---

# Batch rename files with `zmv` in ZSH

<div class="tracking-wide uppercase opacity-70">
  <small>20/06/2022 in #ZSH #scripts #terminal</small>
</div>

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

```sh
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:

```sh
autoload -U zmv
```

It also has some flags for some advanced usages:

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

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

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