Skip to content

Instantly share code, notes, and snippets.

@jneuendorf
Last active October 16, 2024 18:59
Show Gist options
  • Save jneuendorf/85b3e62645c5f1163baa67baec277c75 to your computer and use it in GitHub Desktop.
Save jneuendorf/85b3e62645c5f1163baa67baec277c75 to your computer and use it in GitHub Desktop.
clean macOS files from external drive
#!/bin/bash
# Path to the external drive
EXTERNAL_DRIVE="$1"
# Remove .DS_Store, .Trashes, and Icon files
find "$EXTERNAL_DRIVE" -name ".DS_Store" -delete
find "$EXTERNAL_DRIVE" -name "Icon\r" -delete
find "$EXTERNAL_DRIVE" -name ".Trashes" -exec rm -rf {} +
# Disable Spotlight indexing
sudo mdutil -i off "$EXTERNAL_DRIVE"
sudo rm -rf "$EXTERNAL_DRIVE/.Spotlight-V100"
# Disable .fseventsd logging
sudo touch "$EXTERNAL_DRIVE/.fseventsd/no_log"
# Prevent Trash creation (optional, but must be manually emptied)
rm -rf "$EXTERNAL_DRIVE/.Trashes"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment