I already wrote a post a while ago about how to mass rename files in Unix. But today I was faced with the challenge to do the same trick, except rename each file to an increased number.
I had a whole folder with all kind of PNG images, and I had to rename them to image-1.png , image-2.png , etc…
After a bit of research I finally came up with this one-liner:
c=0 && for f in *.png; do c=$(($c + 1 )) && mv $f image-$c.png; done
What it basically does:
- It sets a variable called $c .
- It starts a for-loop for every PNG file.
- In each iteration it increases $c with 1 and simply renames the file.
I hope that this helps you if you’re trying to achieve the same result.
Visitors give this article an average rating of 4.5 out of 5.
How would you rate this article?
★ ★ ★ ★ ★