Rename file with zmv

batch-renamezsh

I just discovered zmv this morning.

To test it i have created a few files.

test1.txt test2.txt test3.txt

I'm trying to rename them with zmv
I'd like to get this output:

test-1.txt test-2.txt test-3.txt

when I try to use wildcards I get an error message:

zmv '(*)([0-9]{1,})(.txt)' '$1-$2$3'
zmv: error: number of wildcards in each pattern must match

Am i doing something wrong (answer has to be yes 🙂 )

Best Answer

  • Do you only want to add a - to the filename? Try it like this:

    zmv -n 'test(*).txt' 'test-${1}.txt'
    

    The -n switch shows you what would happen without really performing any action.