Skip to content

Instantly share code, notes, and snippets.

@Hotfirenet
Created March 21, 2017 08:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Hotfirenet/bcb1881e5e31b7c1f7f1fbb152637a63 to your computer and use it in GitHub Desktop.
Save Hotfirenet/bcb1881e5e31b7c1f7f1fbb152637a63 to your computer and use it in GitHub Desktop.
Manipulation de fichier en shell
#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