Skip to content

Instantly share code, notes, and snippets.

@redolivedev
Created May 1, 2017 14:45
Show Gist options
  • Save redolivedev/9e4d9209c5205e572782ae95ba59d107 to your computer and use it in GitHub Desktop.
Save redolivedev/9e4d9209c5205e572782ae95ba59d107 to your computer and use it in GitHub Desktop.
Remove special characters that don't show up on smb shares
#!/usr/bin/env bash
find "$1" -depth -print0 | while IFS= read -r -d '' file; do
d="$( dirname "$file" )"
f="$( basename "$file" )"
new=$(sed "s/[<>:;\"/\\|?*]/-/g" <<< "$f")
if [ "$f" != "$new" ]; then
if [ -e "$d/$new" ]; then
echo "Notice: \"$new\" and \"$f\" both exist in "$d":"
ls -ld "$d/$new" "$d/$f"
else
echo "$file"
echo "MOVED '$file' TO '$d/$new'" >> ~/Desktop/log-remove-special-characters.txt
mv "$file" "$d/$new"
fi
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment