Skip to content

Instantly share code, notes, and snippets.

@YanhaoYang
Created September 10, 2017 06:47
Show Gist options
  • Save YanhaoYang/0851f15b260516326ba7ba2fcb23bdd0 to your computer and use it in GitHub Desktop.
Save YanhaoYang/0851f15b260516326ba7ba2fcb23bdd0 to your computer and use it in GitHub Desktop.
Rename files by index
#!/bin/bash
files="*.mp4"
regexp="([0-9]+).mp4"
for i in $files
do
if [[ $i =~ $regexp ]]
then
idx="${BASH_REMATCH[1]}"
name=$(printf "%02d" $idx)
echo "rename \"$i\" -> \"$name - $i\""
#mv "$i" "$name - $i"
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment