Created
March 21, 2017 08:41
-
-
Save Hotfirenet/bcb1881e5e31b7c1f7f1fbb152637a63 to your computer and use it in GitHub Desktop.
Manipulation de fichier en shell
This file contains 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
#trouver les fichiers linux, mac qui n'ont pas les caractères autorisé par Windows | |
find . -name '*[<>:/\\|?*]*' -o -name '*[ \.]' | |
#fonction de renommage en masse des fichiers linux, mac qui n'ont pas les caractères autorisé par Windows | |
#rename.sh | |
#!/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 | |
#trouvé sur https://superuser.com/questions/538161/how-to-bulk-rename-files-with-invalid-encoding-or-bulk-replace-invalid-encoded-c | |
#Utilisation rename.sh /some/path | |
#supprimer le echo aprés vérification |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment