Skip to content

Instantly share code, notes, and snippets.

@sixem
Created June 29, 2021 17:59
Show Gist options
  • Save sixem/7d6ad625f6b877d031c332ebab74ee8a to your computer and use it in GitHub Desktop.
Save sixem/7d6ad625f6b877d031c332ebab74ee8a to your computer and use it in GitHub Desktop.
Sequential rename of files by index
#!/bin/bash
INDEX=0
find . -type f | while read FILE; do
BASENAME=$(basename "$FILE")
EXTENSION="${BASENAME##*.}"
FILENAME="${BASENAME%.*}"
echo "$FILENAME.$EXTENSION -> $INDEX.$EXTENSION"
mv "$FILENAME.$EXTENSION" "$INDEX.$EXTENSION"
INDEX=$((INDEX+1))
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment