A comprehensive system cleanup script that works across Linux, macOS, and Windows (WSL) platforms.
Author: Ahmad
- Cross-Platform Support: Works on Linux, macOS, and Windows (WSL)
- Package Manager Cleanup: Supports APT, YUM, DNF, Pacman, Homebrew, MacPorts
- Comprehensive Cleaning: Removes temporary files, caches, logs, and more
- Safe Operation: Includes dry-run mode and detailed logging
- Memory Optimization: Clears memory caches and system journals
- Docker Cleanup: Removes unused Docker containers and images
- Automated Reporting: Generates disk usage reports
- APT, YUM, DNF, Pacman cache cleanup
- Homebrew and MacPorts cleanup (macOS)
- MSYS2 package cache cleanup (Windows)
- Temporary files (
/tmp
,/var/tmp
, user temp files) - Browser caches (Chrome, Firefox, Edge, Opera, Brave)
- System cache directories
- Old log files (30+ days)
- Downloads folder cleanup (old archives)
- System journal cleanup (systemd/macOS)
- Memory cache clearing
- Trash/Recycle bin emptying
- Old kernel removal (Linux)
- Docker system cleanup
-
Download the script:
git clone <repository-url> # or download shell-cleaner.sh directly
-
Make it executable:
chmod +x shell-cleaner.sh
-
Optional - Add to PATH:
sudo cp shell-cleaner.sh /usr/local/bin/system-cleanup
./shell-cleaner.sh
./shell-cleaner.sh --dry-run
./shell-cleaner.sh --help
- Bash 4.0+
- sudo privileges
- Supported package managers: APT, YUM, DNF, Pacman
- Bash 4.0+
- sudo privileges
- Optional: Homebrew, MacPorts
- Windows Subsystem for Linux (WSL)
- MSYS2 (optional)
The script provides:
- Real-time feedback with colored output
- Detailed logging to
~/system-cleanup.log
- Disk usage report after cleanup
- Warning messages for any issues encountered
ℹ Cross-Platform System Cleanup Tool
ℹ Detected OS: Linux
Cleaning package cache...
✓ APT cache cleaned
Cleaning temporary files...
✓ Temporary files cleaned
Cleaning cache directories...
✓ Cache directories cleaned
...
=== Cleanup completed at Mon Sep 23 15:30:45 UTC 2025 ===
✓ Check /home/user/system-cleanup.log for details
- Dry run mode to preview changes
- Comprehensive logging of all operations
- Error handling with warnings for failed operations
- Age-based deletion (only removes old files)
- Preserves current kernel and essential system files
# Run with sudo if needed for system-wide cleanup
sudo ./shell-cleaner.sh
# Ensure WSL is properly installed
wsl --status
# May need to grant full disk access in System Preferences
# Security & Privacy > Privacy > Full Disk Access
All operations are logged to: ~/system-cleanup.log
Log format:
=== Cross-Platform System Cleanup started at [timestamp] ===
[timestamp]: APT cache cleaned
[timestamp]: WARNING: Some /tmp files couldn't be deleted
[timestamp]: Temporary files cleaned
...
Feel free to submit issues and enhancement requests!