Disk Usage Cheat Sheet: du, df, ncdu and lsblk

Most used

Free space first, then find where it went:

df -h                                  # free space on every filesystem
df -h /home                            # the filesystem that holds /home
du -sh ~/Downloads                     # total size of one folder
sudo du -xh --max-depth=1 / | sort -h  # biggest top-level dirs on /
sudo ncdu -x /                         # interactive browser
df -i                                  # inode usage ("full" with free space?)

df asks each filesystem how full it is. du walks a directory tree and adds up file sizes. Use df to learn which filesystem is full and du (or ncdu) to learn what is filling it. If you are already seeing write failures, follow No space left on device for the full recovery steps.

df: free space per filesystem

CommandWhat it does
df -hAll mounted filesystems, human-readable sizes (powers of 1024)
df -HSame in powers of 1000 (matches the size printed on the drive)
df -h /varOnly the filesystem that contains /var
df -hTAdd the filesystem type (ext4, xfs, btrfs, tmpfs...)
df -h -x tmpfs -x devtmpfs -x squashfsHide RAM-backed and snap loop filesystems
df -h -t ext4Show only one filesystem type
df -iInode usage instead of bytes
df -h --output=source,fstype,size,used,avail,pcent,targetChoose columns
df -h --totalAdd a grand total line
findmnt -Ddf-style view from util-linux, with mount options in findmnt

Example output:

Filesystem      Size  Used Avail Use% Mounted on
/dev/nvme0n1p2  468G  441G  3.6G 100% /
/dev/nvme0n1p1  1.1G   71M  1.0G   7% /boot/efi
tmpfs           3.9G  2.1M  3.9G   1% /tmp

Size minus Used is larger than Avail on ext4 because about 5% is reserved for root by default. That is why a "100%" disk still lets root log in and clean up.

du: size of files and directories

CommandWhat it does
du -sh dirOne total for dir
du -sh *Total for each item in the current directory (hidden files excluded)
du -sh .[!.]* *Include dotfiles and dot-directories
du -h --max-depth=1 dir | sort -hEach subdirectory, smallest to largest (-d 1 is the short form)
du -xh --max-depth=1 /-x: stay on one filesystem (skip /proc, other disks, network mounts)
du -ah dir | sort -rh | head -20The 20 largest files and directories under dir
du -ch *.logSizes plus a grand total of matching files
du -sh --apparent-size fileLogical size instead of disk blocks used (differs for sparse and compressed files)
du -sh --exclude='.git' proj/Skip matching paths
du --inodes -x --max-depth=1 / | sort -nCount files per directory (find what eats inodes)
du -sh --time dir/*Show the newest modification time in each entry

ncdu and other analyzers

CommandWhat it does
sudo apt install ncdu / sudo dnf install ncdu / sudo pacman -S ncdu / sudo zypper install ncduInstall ncdu
ncdu ~Scan and browse your home directory
sudo ncdu -x /Whole root filesystem, without crossing into other mounts
ncdu -o scan.json /srv then ncdu -f scan.jsonScan once (for example on a server), browse later
Keys in ncduArrows/Enter navigate, d deletes, s sorts by size, C by item count, g toggles graph, q quits
gdu /Fast parallel alternative to ncdu (packaged on most distros)
baobab / filelightGraphical analyzers for GNOME and KDE

Disks, partitions and mounts

CommandWhat it does
lsblkTree of disks, partitions, LVM and LUKS volumes with mount points
lsblk -fAdd filesystem type, label, UUID and free space
lsblk -o NAME,SIZE,FSTYPE,FSUSE%,MOUNTPOINTSChoose columns
findmntTree of everything mounted, with options
findmnt /homeWhich device and options back a path
sudo fdisk -lPartition tables of all disks
sudo btrfs filesystem usage /Real usage on Btrfs (df can be misleading with snapshots)
sudo pvs; sudo vgs; sudo lvsLVM physical volumes, volume groups (VFree = unallocated) and logical volumes

Partitioning, resizing and fstab are covered in the disk management guide.

Common recipes

Find the directory that is filling the root filesystem, one level at a time:

sudo du -xh --max-depth=1 / 2>/dev/null | sort -h | tail -8
sudo du -xh --max-depth=1 /var 2>/dev/null | sort -h | tail -8

List the biggest files on a filesystem (more options in the find largest files script):

sudo find / -xdev -type f -size +500M -printf '%s\t%p\n' 2>/dev/null | sort -rn | head -20 | numfmt --field=1 --to=iec

Space is used but you cannot find the files: look for deleted files still held open:

sudo lsof +L1
# restart the process holding them, for example:
sudo systemctl restart rsyslog

Shrink the systemd journal (see the journalctl cheat sheet):

journalctl --disk-usage
sudo journalctl --vacuum-size=500M

Clean package caches:

sudo apt clean && sudo apt autoremove --purge     # Debian, Ubuntu, Mint
sudo dnf clean all && sudo dnf autoremove          # Fedora
sudo paccache -rk2                                # Arch (pacman-contrib), keep 2 versions
sudo zypper clean --all                           # openSUSE

Find old disabled snap revisions and Flatpak leftovers:

snap list --all | awk '/disabled/{print $1, $3}'
flatpak uninstall --unused

Check the size of Docker data:

docker system df
docker system prune     # removes stopped containers, unused networks, dangling images

Gotchas

  • du and df disagree. Open deleted files, reserved blocks, snapshots (Btrfs, LVM) and files hidden under a mount point all count for df but not du. To see files hidden under a mount point, bind-mount the parent: sudo mount --bind / /mnt and run du on /mnt.
  • Forgetting -x. du / without -x walks /proc, network shares and every other disk, takes ages and gives a meaningless total.
  • du -sh * skips dotfiles. In a home directory most space is often in .cache, .local/share or .var/app (Flatpak).
  • Inodes can run out first. Millions of tiny files (mail queues, session files, node_modules) give "No space left on device" with free bytes. Check df -i.
  • Do not delete active logs with rm. The process keeps writing to the deleted file and the space is not freed. Truncate instead: sudo truncate -s 0 /var/log/big.log.
  • Units. -h means 1024-based (GiB, shown as G); drive makers use 1000-based. A "500 GB" SSD shows as about 466G.

Option references: du(1), df(1) and lsblk(8).

Frequently asked questions

How do I check free disk space on Linux?

Run df -h. It lists every mounted filesystem with its size, used and available space in human-readable units. df -h / shows only the root filesystem.

How do I see the size of a folder?

Use du -sh /path/to/folder. -s prints one total and -h uses K, M and G. For each subfolder, use du -h --max-depth=1 /path | sort -h.

Why do du and df show different numbers?

df reports what the filesystem has allocated, including files that were deleted but are still held open by a process, reserved blocks and metadata. du only adds up files it can see. Find deleted-but-open files with sudo lsof +L1.

Why does df say the disk is full when du shows free space?

Usually a process still has a deleted file open (often a log), or the filesystem is out of inodes. Check df -i and sudo lsof +L1, then restart the process that holds the file.

What is the best disk usage analyzer for the terminal?

ncdu. It scans a directory once and lets you browse and delete with the arrow keys. Install it with your package manager; desktop alternatives are Baobab (GNOME Disk Usage Analyzer) and Filelight (KDE).

Spotted a mistake or a command that no longer works? Send a correction — pages are re-checked when reports come in.