photo credit: hermzz via photopin cc

Mass rename files in Unix with iteration index

Tags: ,

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:

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?

Leave a Reply