This open-source Bash script is designed to clean various types of files and directories on your macOS system. It helps in freeing up disk space by removing logs, cache files, .DS_Store
files, and other unnecessary temporary files. It also restarts network services, cleans Time Machine snapshots, updates the Spotlight index, and cleans Dock data sources to ensure your system runs smoothly.
Changes Made:
- Introduced a function clean_external_drives to detect and clean mounted external drives and USB devices.
- The script now scans for external devices, checks their mount points, and applies the safe_rm function to clean them.
- Added color-coded output messages to indicate the status of each cleaning operation more clearly.
- Refactored existing code for better readability and maintainability.
- Ensured that all primary cleaning operations are maintained and enhanced with the new external drive cleaning capability.
- The script performs comprehensive system cleaning, including cache files, logs, temporary files, Time Machine snapshots, and more.
- External drives and USB devices are now included in the cleaning process, ensuring that all connected storage devices are cleaned.
- Usage:
- Run the script as usual. The cleaning of external drives and USB devices will be handled automatically if they are detected and mounted.
Removing .DS_Store files...Done!
Cleaning cache files...Done!
Restarting network services...Done!
Cleaning system logs and crash reports...Done!
Cleaning temporary files...Done!
Removing items from trash...Done!
Cleaning Time Machine snapshots...Done!
Updating Spotlight index...Done!
Cleaning Dock data sources...Done!
Cleaning external drives...
Cleaning /Volumes/ExternalDrive1...Done!
Cleaning /Volumes/USBDevice1...Done!
Free space after cleaning: 50G
- This update significantly enhances the script's functionality, making it a more robust and versatile cleaning tool for macOS systems.
-
Removes
.DS_Store
files. -
Cleans cache directories.
-
Restarts network services.
-
Cleans system logs and crash reports.
-
Removes temporary files.
-
Removes File Remnants
-
Empties the Trash.
-
Cleans Time Machine snapshots.
-
Updates Spotlight index.
-
Cleans Dock data sources.
-
Provides a summary of free disk space after cleaning.
-
Supported macOS Versions This script should work on most versions of macOS.
-
Important Note: Please note that some files may require administrator permissions to be deleted. These files are typically system-related or protected, and the script will skip them to prevent any unintended consequences. It’s recommended to run the script with superuser privileges (sudo ./clean_mac_temp_files.sh) to ensure proper access and cleaning of temporary files.
Download the script from the GitHub repository.
Save the script to your desired location on your macOS system.
Open Terminal and navigate to the script's directory. Run the following command to make the script executable:
chmod +x clean_mac_temp_files.sh
sudo ./clean_mac_temp_files.sh