Last active
February 28, 2018 16:05
-
-
Save auxiliary/9d809c014f7fff79447fe93ff7593fea to your computer and use it in GitHub Desktop.
Rename all files sequentially to numbers
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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