df and du in Linux: disk space

Updated November 1, 2026

df shows free space on filesystems, and du shows the size of directories and files.

Common cases

df -h                  # free and used per filesystem
df -h /                # the root filesystem only
du -sh /etc            # a directory's total size on one line
du -sh ~/* | sort -rh  # the biggest items on top

Sample output

$ df -h /
Filesystem      Size  Used Avail Use% Mounted on
overlay         206G   43G  164G  21% /
$ du -sh /usr/share
61M	/usr/share
$ du -sh /usr/share/* | sort -rh | head -3
41M	/usr/share/vim
5.8M	/usr/share/doc
5.5M	/usr/share/man

How it works: df and du count differently

df asks the filesystem how many blocks are free - fast, and independent of the file count. du walks the tree and adds up each file's size - slow on large directories. That is why the totals disagree: a file that is deleted but still held open by a process frees no space, so df still counts that space as used, but du does not. Inodes are a separate resource, shown by df -i.

Common mistakes

du -sh * misses hidden files: the shell does not expand * into names that start with a dot. In a directory holding .cache at 40 MB and visible at 2 MB, du -sh * prints 2.0M visible while du -sh . prints 42M .. When you hunt for missing space, measure the directory itself: du -sh . or du -sh .[!.]* *.

Without permissions du undercounts quietly. As an ordinary user, du -sh /etc prints du: cannot read directory '/etc/ssl/private': Permission denied and then the total 2.2M, which leaves that directory out. The message goes to stream 2, so du -sh /etc 2>/dev/null hides it while the total stays low. Measure other people's directories with sudo.

In df output the Size column is not Used plus Avail. A filled 56M ext4 reads 56M 52M 468K 100%: ext4 keeps about 5% of the blocks in reserve for root, and Avail for an ordinary user leaves them out. That is why root wrote another 3 MB after df had shown 468K. The reserve is visible in tune2fs -l: Block count 16384, Reserved block count 819.

Used in

You need this in the lesson Capacity planning. The theory is the chapter Capacity planning.

See also

Free inodes: df -i.

Try it

Open the sandbox: a real throwaway Linux terminal in your browser. Run the commands above by hand - the container is deleted when you leave.