Created
July 20, 2017 17:42
-
-
Save Philmod/f88d24e056df58fb74a340e1ccb2e437 to your computer and use it in GitHub Desktop.
Script to remove special accents in file and directory names
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
#!/usr/bin/env bash | |
find "$1" -depth -print0 | while IFS= read -r -d '' file; do | |
d="$( dirname "$file" )" | |
f="$( basename "$file" )" | |
new="${f//[^a-zA-Z0-9\/\._\-]/}" | |
if [ "$f" != "$new" ] # if equal, name is already clean, so leave alone | |
then | |
if [ -e "$d/$new" ] | |
then | |
echo "Notice: \"$new\" and \"$f\" both exist in "$d":" | |
ls -ld "$d/$new" "$d/$f" | |
else | |
echo mv "$file" "$d/$new" # remove "echo" to actually rename things | |
fi | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment