At a high level, the disk space debugging process looks like this:
- Use
dfto see total disk usage and remaining available space. - Use
duto drill down into specific directories and locate the largest files. - Keep narrowing the search until you find the offending files or directories.
These example commands give you a quick diagnostic toolkit that can be run on almost any Linux or Unix system.
Back to topCheck overall disk usage
To see total disk space and remaining available space across all mounted filesystems use:
df -hBack to top
Identify large files and directories
To list the top 10 largest files/directories in the current directory in a human-readable format:
du -sh * | sort -rh | head -10du -sh * | Summarizes (-s) the disk usage of all files and directories in the current location in a human-readable format (-h). |
|---|---|
sort -rh | Sorts the output in reverse order (-r) based on human-readable numerical values (-h). |
head -10 | Displays only the top 10 entries from the sorted list. |
This helps you quickly reveal the biggest files and directories so you know where to continue debugging. You can navigate into a large directory and rerun the command to further drill down to narrow the results.
Back to topAdditional examples worth knowing
These additional examples help expand the debugging toolkit and are commonly used when tracking down disk space problems.
Show disk usage for a specific filesystem
df -h /varThis limits the output to the filesystem containing /var, which can be helpful on systems with many mounted volumes.
Show inode usage
Sometimes disks appear full even when space remains because inodes are exhausted.
df -iIf inode usage hits 100%, the system cannot create new files even though disk space exists.
Find the largest files across the entire filesystem
find / -type f -size +500M -exec ls -lh {} \; | awk '{ print $9 ": " $5 }'This lists files larger than 500 MB across the entire system.
Drill into a single directory more interactively
du -h --max-depth=1This shows directory sizes one level deep, making it easier to navigate large trees step by step.
Sort files by size using ls
ls -lhSThis sorts files in the current directory by size, largest first.
Back to top