Skip to content

Instantly share code, notes, and snippets.

@auxiliary
Last active February 28, 2018 16:05
Show Gist options
  • Save auxiliary/9d809c014f7fff79447fe93ff7593fea to your computer and use it in GitHub Desktop.
Save auxiliary/9d809c014f7fff79447fe93ff7593fea to your computer and use it in GitHub Desktop.
Rename all files sequentially to numbers
#!/bin/bash
if [[ "$#" -ne 1 ]]; then
echo "Usage: ./rename.sh .<extension>";
echo "Example: ./rename.sh .png";
exit
fi
# Set file extension from outside
extension=$1
SAVEIFS=$IFS
IFS=$(echo -en "\n\b")
counter=0
for i in `ls -t *$extension`; do
name=$(printf "%05d" $counter)
mv $i $name$extension
counter=$(( counter+1))
done;
IFS=$SAVEIFS
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment