Rename specific files by inserting zeros to filename


Question

How do I rename files from

p1.py p2.py ... p99.py

to

p001.py p002.py ... p099.py

In zsh running on Ubuntu

Why

I don’t like the way files appear as shown below (p6.py is between p59.py and p60.py)

Rename specific files by inserting zeros to filename

here is solutions:

I know you bored from this bug, So we are here to help you! Take a deep breath and look at the explanation of your problem. We have many solutions to this problem, But we recommend you to use the first method because it is tested & true method that will 100% work for you.

Solution 1

With zmv and the left padding parameter expansion flag:

autoload -Uz zmv # best in ~/.zshrc
zmv -n 'p(<0-999>).py' 'p${(l[3][0])1}.py'

Remove the -n (dry-run) to actually do it.

Note: Use and implement solution 1 because this method fully tested our system.
Thank you 🙂

All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply