I was trying to figure out a solution for this question using zmv
. I am unable to find an exact solution using zmv
. This is what I could come up with so far.
From here, I could rename all files like 1.jpg
, 2.jpg
, 34.jpg
etc as 001.jpg
, 002.jpg
and 034.jpg
using the command,
zmv '(<1->).jpg' '${(l:3::0:)1}.jpg'
Now, I need to modify zmv
to have some patterns in the beginning so that I can rename the files. However, I am not able to accomplish this. The closest I could find is this solution.
c=1 base='0-' zmv '*.jpg' '${base}${(l:3::0:)$((c++))}.jpg'
However, the problem with the above approach is if I have files as 0-1.jpg
, 0-44.jpg
, the above command will replace it as 0-001.jpg
and 0-002.jpg
instead of 0-001.jpg
and 0-044.jpg
.
How should I modify the zmv
command to accomplish the renaming as desired?
Best Answer
You can use -l expansion flag:
Try: