You can use the rename command:
c=0 rename 's/.*/sprintf("file%02d.png", ++$ENV{c})/e' *.png
Use the -n flag if you want to do a test first:
c=0 rename -n 's/.*/sprintf("file%02d.png", ++$ENV{c})/e' *.png
The way this works is, for each argument, it executes the perl s///
expression, and performs the rename from the original to the replaced string. In the replacement string I use sprintf
to format the name, where I use the environment variable c
as the counter from 1.
Or you can use a simple loop counter:
j=1; for i in *.png; do mv "$i" file"$j".png; let j=j+1; done
If you want to pad with 0 for 2-digit numbers:
j=1; for i in *.png; do mv "$i" file$(printf %02d $j).png; let j=j+1; done