Introduction / Why This Matters
A full disk in Ubuntu leads to system slowdowns, failed updates, and service startup errors. Regular monitoring helps you quickly identify hidden space consumers and prevent critical issues. In this guide, you’ll learn how to check storage usage via the terminal and graphical tools, locate the largest directories, and safely free up disk space.
Prerequisites / Preparation
You’ll need Ubuntu 20.04, 22.04, or a newer release to follow this guide. Most commands run in the default terminal without requiring additional software. For interactive directory analysis, we recommend the ncdu utility, which isn’t included in the base installation. Make sure you have access to an account with sudo privileges.
Step 1: Check Overall Disk Usage
First, assess the overall state of your file system. Open a terminal (Ctrl + Alt + T) and run:
df -h
The df (disk free) command displays all mounted partitions. The -h flag formats the output into human-readable units (GB/MB). Pay attention to the Used and Available columns, along with the / mount point. If root partition usage exceeds 85%, it’s time to hunt down large files.
Step 2: Find the Largest Files and Directories
To see exactly which directories are taking up space, use the du (disk usage) utility. The standard command recursively scans directories, but the output can be overwhelming. Filter the top 15 folders in your home directory:
du -h ~/ | sort -rh | head -n 15
The -h flag enables human-readable formatting, sort -rh sorts from largest to smallest, and head limits the output.
For a more convenient analysis, we recommend installing ncdu:
sudo apt update && sudo apt install -y ncdu
To scan the system root:
sudo ncdu /
The interface allows you to navigate directories using the arrow keys, delete files by pressing d, and refresh the data with u.
Step 3: Automatically Clear System Cache and Logs
After identifying large directories, it’s safest to start with system caches. The APT package manager stores downloaded .deb archives that are no longer needed for installation. Clear them with:
sudo apt clean
Next, remove automatically installed dependencies that are no longer required by any package:
sudo apt autoremove -y
The systemd system journal can also grow to several gigabytes. Check the current log size:
journalctl --disk-usage
If the size exceeds 1 GB, limit log retention to the last three days:
sudo journalctl --vacuum-time=3d
💡 Tip: Configure log rotation in
/etc/systemd/journald.confby changing theSystemMaxUse=200Mparameter. This will prevent disk overflow in the future.
Verify the Results
After performing the cleanup, run df -h again and compare the values in the Available column for the root partition. The difference should match the amount of freed cache and log space. Also, ensure that key services (e.g., apache2, docker, or snapd) start without write errors. Run systemctl --failed to check the status of active services.
Troubleshooting
Operation not permittederror when deleting files. You are trying to modify files owned byrootor other services. Always usesudofor system directories, and do not delete contents in/etcor/usrwithout understanding their purpose.ncdushows 0 size or hangs on/procand/sys. These virtual file systems do not consume disk space. Runncduwith the-xflag to exclude pseudo-filesystems and network shares from the scan:sudo ncdu -x /.- Disk space isn't freed after cleanup. Files may have been deleted but are still held open by active processes. Reboot the system or locate these lingering processes using
sudo lsof +L1and restart the corresponding services.