Skip to content

Instantly share code, notes, and snippets.

@kyletimmermans
Created July 3, 2024 14:16
Show Gist options
  • Save kyletimmermans/fd321c3ddae1fb5fe2b5214bc00f6bd4 to your computer and use it in GitHub Desktop.
Save kyletimmermans/fd321c3ddae1fb5fe2b5214bc00f6bd4 to your computer and use it in GitHub Desktop.
Useful script to remove extra MacOS metadata files when moving files from MacOS to Linux. Also remove any Solidus characters (slash) from filenames which are allowed on Mac but not in Linux
# Remove .DS_Store Files
find . -name ".DS_Store" -type f -delete
# Remove AppleDouble Files
find . -name '._*' -exec rm {} \;
# Change Any Illegal Solidus Chars in Filename to Fraction Slash
TARGET_CHAR=$(echo -ne '\xef\x80\xa2')
REPLACEMENT_CHAR="⁄"
find . -depth -name "*$TARGET_CHAR*" -print0 | while IFS= read -r -d '' file; do
new_file=$(echo "$file" | sed "s/$TARGET_CHAR/$REPLACEMENT_CHAR/g")
sudo mv "$file" "$new_file"; done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment