Created
November 12, 2017 20:27
-
-
Save johnjreiser/6f15801d232f802e8265db9e18c854f6 to your computer and use it in GitHub Desktop.
Rename files from MM-DD-YYYY to YYYY-MM-DD
This file contains hidden or 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 | |
for file in `ls -1 | grep -e "[0-9]\{2\}-[0-9]\{2\}-[0-9]\{4\}" ` ; do | |
if [[ $file =~ ([0-9]{2})-([0-9]{2})-([0-9]{4})(.*)$ ]] ; then | |
newname=${BASH_REMATCH[3]}-${BASH_REMATCH[1]}-${BASH_REMATCH[2]}${BASH_REMATCH[4]} | |
echo "$file -> $newname " | |
mv -i $file $newname | |
else | |
echo Skipping $file... | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment