Skip to content

Instantly share code, notes, and snippets.

@Philmod
Created July 20, 2017 17:42
Show Gist options
  • Save Philmod/f88d24e056df58fb74a340e1ccb2e437 to your computer and use it in GitHub Desktop.
Save Philmod/f88d24e056df58fb74a340e1ccb2e437 to your computer and use it in GitHub Desktop.
Script to remove special accents in file and directory names
#!/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