Skip to content
Log In Sign Up info@muvcloud.com

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

OptionWhat it does
-sOne total per argument
-hReadable sizes
-aLists files, not only folders
-d 1Goes one level deep
-cAdds a grand total
-xStays on one file system
--excludeSkips matching paths
--apparent-sizeCounts 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 +L1 lists 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 df splits the space by images, containers, and volumes.
  • Package cache: sudo du -sh /var/cache/apt or /var/cache/dnf

Updated:

Linux VPS with Full Root Access

MUVCloud cloud servers run on KVM with Enterprise NVMe SSD storage and full root access, in Turkey, the Netherlands, and the USA.

Cloud VPS Plans Starting at2.99 $/mo Cheap Linux VPS

No Limits on Service or Support

You are not on your own as your projects grow. Our support engineers are ready 24/7, on several channels, whenever you need them.

Support specialist
  • 100% customer satisfaction goal
  • Our own hardware
  • 24/7 ticket and email support
  • 4 countries with locations