Gain control over your system's storage efficiently.
Understanding how your disk space is being utilized is crucial for maintaining optimal system performance and preventing unexpected storage full errors. This guide will walk you through the common methods for analyzing and managing disk usage.
Several powerful command-line tools can help you pinpoint where your storage is going:
du
(Disk Usage)The du
command estimates file space usage. It can be used to show the disk usage of files and directories.
du -h
(Human-readable format, e.g., KB, MB, GB)du -sh /path/to/directory
(Shows total size of a specific directory)du -h /path/to/directory | sort -rh
(Lists directories sorted by size, largest first)# Example: Check disk usage in the current directory, sorted by size
du -h . | sort -rh | head -n 10
df
(Disk Free)The df
command reports file system disk space usage. It shows the total size, used space, and available space for mounted file systems.
df -h
(Human-readable format)df -i
(Useful if you're running out of inodes, not just space)# Example: Display disk space for all mounted file systems
df -h
ncdu
(NCurses Disk Usage)ncdu
is an excellent interactive ncurses-based disk usage analyzer. It provides a user-friendly interface to navigate and delete files.
sudo apt install ncdu
or sudo yum install ncdu
).ncdu /path/to/directory
Once running, you can use arrow keys to navigate, press 'd' to delete selected items, and '?' for help.
/var/log
, applications can generate very large log files if not properly managed./tmp
and /var/tmp
can accumulate old temporary files.du
and df
periodically to stay informed.sudo apt autoremove && sudo apt clean
sudo dnf autoremove && sudo dnf clean all
logrotate
to compress and delete old logs. Manually clear logs if necessary, but be cautious./tmp
, but be aware that some running processes might be using files there. A reboot often clears /tmp
.du
or ncdu
to find the largest offenders and decide if they can be removed, archived, or moved elsewhere.docker system prune -a
to remove unused images, containers, and volumes./usr
, /lib
) unless you know exactly what you are doing.Effective disk space management is an ongoing process. By understanding the tools available and implementing regular checks and cleanup routines, you can ensure your system remains healthy and performant, free from storage-related issues.
Explore More Guides