LinuxClean is a conservative, scriptable maintenance tool for Debian/Ubuntu-like Linux systems. It reports the machine state, previews eligible files, asks before destructive actions, and supports unattended jobs through explicit command-line options.
- Quick, standard, full, and custom cleanup modes.
--dry-runpreview with no filesystem or package changes.- Size-sorted candidates and reclaim estimates, capped at the 20 largest files by default for readable audits.
- Age-based cleanup for
/tmpand user caches (7 days by default), protecting fresh/active files. - APT cache cleanup through
apt-get clean. - systemd journal vacuuming with a validated size target.
- Old-kernel detection that protects both the running kernel and the newest fallback, and only targets versioned
linux-image-*packages. - Handles root plus regular local users, or one selected user with
--user. - English/Chinese output, automatic locale detection, optional log file, lock, color control, and useful exit codes.
- Bash 4+ (Bash 5 recommended)
- Root privileges (
sudoor a root shell) - Optional tools are detected at runtime:
apt-get,dpkg-query,journalctl,getent,nproc, andfree.
chmod +x LinuxClean.sh
# Interactive menu
sudo ./LinuxClean.sh
# Safe preview first
sudo ./LinuxClean.sh --mode standard --keep-days 14 --dry-run
# Show only the 10 largest file candidates
sudo ./LinuxClean.sh --mode full --dry-run --max-items 10
# Unattended daily job
sudo ./LinuxClean.sh --mode quick --yes --log-file /var/log/linuxclean.log
# Full cleanup with a larger journal retention limit
sudo ./LinuxClean.sh --mode full --journal-size 1G| Option | Meaning |
|---|---|
-m, --mode MODE |
quick, standard, full, or custom |
-y, --yes |
Skip confirmations (use with a reviewed mode) |
--dry-run |
Print candidates/commands without changing anything |
--keep-days N |
Remove only files older than N days; default 7 |
--max-items N |
Show at most N file candidates in dry-run; default 20, 0 hides item details |
--journal-size SIZE |
Journal target such as 100M or 1G |
--user USER |
Limit cache cleanup to one local user |
| `--language en | zh` |
--no-color |
Disable ANSI colors |
--log-file FILE |
Tee output to a log file |
-h, --help / -V, --version |
Show help/version |
If stdin is not a terminal, --mode is required. This prevents a scheduled job from hanging at an interactive prompt.
LinuxClean deliberately avoids broad recursive deletion:
/tmpand~/.cachefiles are removed only when older than--keep-days; empty directories are removed afterwards.- APT is cleaned through its package-manager command rather than deleting package files directly.
- The running kernel and newest fallback kernel are protected. Meta packages and unversioned package names are not candidates.
- Every destructive mode prompts by default. Review
--dry-runoutput before using--yesin automation. - A process lock prevents two cleanup jobs from running at the same time.
The tool does not remove documents, photos, application data, databases, or arbitrary paths outside the cleanup targets.
Run the local smoke tests:
./test-i18n.sh
bash -n LinuxClean.shThe script was also checked on a Debian 11 host (5.10.0-32-amd64) using quick, standard, and full dry-runs. It correctly reported /tmp, root caches, APT, journal estimates, and kernel protection without changing the host.
See the repository license and changelog for project history.