cleardocker is a comprehensive cleanup script for Debian-based systems (like Debian, Ubuntu, etc.) designed to free up significant disk space by removing unnecessary files, packages, and Docker resources.
- APT Cleanup: Cleans package cache (
/var/cache/apt) and removes orphan packages (autoremove). - Old Kernel Removal: Purges old, unused kernel images that are safe to remove.
- Log Trimming: Reduces the size of systemd journal logs to a configured limit (200MB).
- Temporary File Cleanup: Cleans
/tmpand/var/tmp. - Orphan Library Removal: Uses
deborphanto find and remove unused libraries. - Snap & Flatpak: Removes disabled Snap packages and unused Flatpak runtimes.
- Docker Cleanup: Prunes stopped containers, dangling images, and unused volumes.
- User Caches: Cleans caches in all user home directories.
cleardocker can be installed from a dedicated APT repository, allowing for easy installation and updates.
First, add the GPG key used to sign the packages. This ensures the authenticity of the software.
curl -sS 'https://keyserver.ubuntu.com/pks/lookup?op=get&search=0xDB97C87E0047334C67C87184B9C6413510FA0858' | sudo gpg --dearmor -o /usr/share/keyrings/cleardocker-keyring.gpgNext, add the cleardocker repository to your system's software sources.
echo "deb [signed-by=/usr/share/keyrings/cleardocker-keyring.gpg] https://tdamiao.github.io/cleardocker/apt/ ./" | sudo tee /etc/apt/sources.list.d/cleardocker.listFinally, update your package list and install cleardocker.
sudo apt-get update
sudo apt-get install cleardockerAfter installation, simply run the script with sudo:
sudo cleardockerThe script must be run as root to perform system-wide cleanup tasks.
The script provides detailed, real-time feedback on its actions. Here's what to look for:
📊 Disk usage BEFORE: Shows the state of your disk before the cleanup begins.🧹 APT – cache & orphans: Details the removal of old package files and unused dependencies.🧹 Removing old kernels: Lists any old kernel versions being removed.🧹 Trimming systemd logs: Shows how much log space was freed.🐳 Docker cleanup: Reports on pruned containers, images, and volumes, and shows a final summary of Docker's disk usage.💾 Disk usage AFTER: Shows the state of your disk after the cleanup, allowing you to see how much space was recovered.
cleardocker does not schedule itself to run automatically. If you wish to have it run on a weekly basis, you can add it to the root user's crontab.
-
Open the root crontab editor:
sudo crontab -e
(If prompted, choose a text editor like
nano.) -
Add the following line to the end of the file:
0 3 * * 1 /usr/sbin/cleardocker >> /var/log/cleardocker.log 2>&1This configuration will run
cleardockerevery Monday at 3:00 AM and save a log of its execution to/var/log/cleardocker.log. -
Save the file and exit the editor.
Contributions are welcome and appreciated! This project is open-source, and you can help in many ways:
- Reporting Bugs: If you find a bug, please open an issue on the GitHub repository.
- Suggesting Enhancements: Have an idea for a new feature or an improvement? Open an issue to discuss it.
- Submitting Pull Requests: If you want to contribute code, please fork the repository, create a new branch for your feature or fix, and submit a pull request.
If you want to build the .deb package from the source code, you'll need the following tools:
sudo apt-get install build-essential devscriptsThen, from the project's root directory, run the debuild command:
# This command builds the binary package without signing it
debuild -b -uc -usThe resulting .deb file will be created in the parent directory.
This project is licensed under the MIT License.
