Last active
February 18, 2026 22:08
-
-
Save kyletimmermans/fd321c3ddae1fb5fe2b5214bc00f6bd4 to your computer and use it in GitHub Desktop.
Useful script to remove extra MacOS metadata files and modify illegal/unrecognized filenames when moving files from MacOS to Linux
This file contains hidden or 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
| #!/usr/bin/env bash | |
| # Remove .DS_Store Files | |
| find . -name ".DS_Store" -type f -delete | |
| # Remove AppleDouble Files | |
| find . -name '._*' -exec rm {} \; | |
| find . -name ".AppleDouble" -type f -delete | |
| # 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 | |
| # Change unrecognized Mac quotes to ones recognized by Linux | |
| TARGET_CHAR=$(echo -ne '\xef\x80\xa0') | |
| 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 | |
| # Just in case none of this works or you need something else, try: https://www.geraldonit.com/apple-afp-to-smb-migration-removing-appledouble-and-_-files-and-converting-file-names-from-unicode-nfd-to-nfc/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment