Linuxlab

df and du in Linux: disk space

Updated July 3, 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

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.

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.