Efficient storage management is critical in Linux, whether you’re running a personal server or managing enterprise infrastructure. Monitoring directory size and disk usage helps prevent performance bottlenecks, optimise resource allocation, and detect early signs of issues like malware or runaway log files.
This guide shows you how to monitor directory size using the du command and track overall disk usage with df, helping you maintain a responsive and secure system.
The du (disk usage) command is ideal for checking the size of directories and subdirectories. It offers flexible options for different reporting formats and depth levels.
To view the size of a specific directory and its subdirectories in kilobytes:
du /path/to/directory
For easier interpretation of sizes in KB, MB, or GB:
du -h /path/to/directory
To avoid overly detailed results, restrict how deep du scans:
du -h --max-depth=1 /path/to/directory
This is especially useful when scanning high-level directories like /home or /var.
To display just the total size of a directory:
du -sh /path/to/directory
To locate the largest directories within a location:
du -h --max-depth=1 / | sort -rh
This sorts the output in descending order by size, making it easy to pinpoint storage-heavy areas.
The df (disk free) command provides insights into disk space usage across all mounted file systems.
Inodes store metadata for files. If your system runs out of inodes, new files can’t be created even if space is available:
df -i
To see disk usage across all partitions:
df
This includes total size, space used, available space, and the usage percentage.
To display results in a clearer format:
df -h
Target a particular partition or mount point for more focused monitoring:
df -h /dev/sda2
To identify the format of each mounted file system (e.g., ext4, xfs, tmpfs):
df -T