Size of One Folder
du -sh /var/www
sudo du -sh /var/log /var/lib/docker /home
-s prints one total per folder instead of a line for every subfolder, and -h prints sizes as K, M, and G. Without sudo, du cannot read some folders, prints "permission denied" for them, and reports a total that is too low. On Ubuntu 26.04 du comes from the Rust rewrite of the core commands; the options in this guide work the same there.
Options
| Option | What it does |
|---|---|
-s | One total per argument |
-h | Readable sizes |
-a | Lists files, not only folders |
-d 1 | Goes one level deep |
-c | Adds a grand total |
-x | Stays on one file system |
--exclude | Skips matching paths |
--apparent-size | Counts bytes, not blocks |
-d 1 is the short form of --max-depth=1.
List Subfolders by Size
sudo du -h --max-depth=1 /var | sort -rh | head -15
This shows the fifteen largest folders directly below /var. sort -h understands the K, M, and G suffixes, and -r puts the largest first; see the sort command guide. Repeat the command inside the largest folder until you reach the cause. To include single files, add -a:
sudo du -ah /var/log | sort -rh | head -20
For a search by file size across the whole disk, see how to find large files in Linux.
Stay on One File System and Exclude Paths
sudo du -xh -d 1 / 2>/dev/null | sort -rh | head
du -sh --exclude="node_modules" --exclude="*.log" ~/app
-x skips /proc, /sys, other mounted disks, and network shares, which otherwise make du slow or the totals misleading. 2>/dev/null hides error messages about files that vanish while du runs. --exclude takes a shell pattern; quote it so your shell does not expand it.
Apparent Size vs Disk Usage
du -h disk.img
du -h --apparent-size disk.img
ls -lh disk.img
du normally counts the blocks a file occupies; --apparent-size and ls -l count the bytes in it. The two differ in both directions. A tiny file still takes a whole block, often 4 KB, so a folder of millions of small files uses more space than its bytes suggest. A sparse file, such as a virtual disk image, can show many gigabytes in ls -l and use far less on disk.
Why du and df Disagree
- Deleted files still open: a program holds a deleted log open, so df counts the space and du cannot see the file.
sudo lsof +L1lists such files; restarting the program frees the space. See the lsof command guide. - Files hidden under a mount point: files written to a folder before a disk was mounted on it stay on the main disk, invisible to du. A bind mount of
/to a temporary folder shows them; unmount it afterwards. - Reserved blocks: ext4 keeps a share of the disk for root by default, about 5 percent, which df leaves out of the available space.
- Folders du could not read: run it with sudo.
Reading df itself is covered in how to check disk space in Linux, and a full disk in no space left on device.
Large Trees and Busy Servers
On a folder with millions of files, du reads every directory entry and can slow a busy disk. Give it the lowest priority:
sudo nice -n 19 ionice -c3 du -sh /srv/data
For an interactive view, install ncdu and run sudo ncdu -x /: it shows folders by size and lets you walk through them with the arrow keys.
Quick Checks
- Home folders:
sudo du -sh /home/* - The system journal:
journalctl --disk-usage - Docker:
docker system dfsplits the space by images, containers, and volumes. - Package cache:
sudo du -sh /var/cache/aptor/var/cache/dnf