I have multiple gif files in a directory with different names.
How can i rename them to have this result:
file01.gif
file02.gif
file03.gif
.
.
.
file0500.gif
Thanks for your help.
I have multiple gif files in a directory with different names.
How can i rename them to have this result:
file01.gif
file02.gif
file03.gif
.
.
.
file0500.gif
Thanks for your help.
#! /bin/bash
y=1;
for x in *.gif;
do mv $x file0$y.gif;
y=$[$y+1];
done;
POSIX (works in any compliant Unix shell)
i=1
for f in *.gif; do
echo mv "$f" file$i.gif
i=$((i+1))
done
If you like the result, remove "echo" in the example above to perform the actual renames. The quotes around $f are necessary in case there are difficult file names (for instance with spaces)..
If you want leading zeroes you can replace the mv statement with something like this (4 positions):
mv "$f" file$(printf "%04d" $i).gif
# for i in `ls file0*.gif` ; do mv -v $i ${i}_new ; done
`file01.gif' -> `file01.gif_new'
`file02.gif' -> `file02.gif_new'
`file03.gif' -> `file03.gif_new'