Bash script to clean up disk space for Linux
Bash script to clean up disk space for Linux
A handy interactive Bash script to inspect and optionally clean up disk space used by common development tools and system caches on Ubuntu (or any Linux system).
What it does
- Scans common dev tool folders (e.g.
.npm,.yarn,.m2,.gradle,.nvm,snap, etc.) and shows their sizes. - Prompts for deletion of each folder individually.
Reports disk usage of:
- APT package cache
journalctlsystem logs- Docker system (images, volumes, containers)
Prompts separately before cleaning:
- APT cache (
sudo apt autoremove && apt clean) - Systemd journal logs (
journalctl --vacuum-time=7d) - Docker unused data (
docker system prune -a)
- APT cache (
Features
- Simple interactive prompts for safe manual control
- Works well on local dev machines or CI runners with disk pressure
- Requires no dependencies besides standard Linux tools
Usage
Download and run:
1
2
chmod +x check-disk-usage.sh
./check-disk-usage.sh
Or run directly from Gist in one line:
1
bash <(curl -L https://go.khuong.dev/check-disk-usage)
References
This post is licensed under CC BY 4.0 by the author.
