Linux: How to Check Disk Space (df, du, lsblk)
Tue Aug 19th, 2025 — 23 hours ago

Linux: How to Check Disk Space?

Problem

  • You need to see how much free disk space is available and where space is used.
  • You want quick, reliable terminal commands for system-wide and per-directory checks.

Solutions

Show filesystem free/used space (human-readable):

df -h
# Linux & macOS: overview of all mounted filesystems

Check the current filesystem only (where you are):

df -h .
# Linux & macOS: useful when working inside a specific path

Show filesystem type (Linux) for context:

df -hT
# Linux: adds a "Type" column; macOS lacks -T

Summarize a directory’s total size:

du -sh /path/to/dir
# Linux & macOS: one-line total (human-readable)
  • See which subfolders are largest (top-level view).
du -sh /path/to/dir/* | sort -h
# Linux & macOS: quick triage of space hogs
  • List disks/block devices.
lsblk -f
# Linux: shows devices, mountpoints, and filesystems

diskutil list
# macOS: lists disks/partitions; use 'diskutil info /' for the root volume
  • Check inode exhaustion (no inodes = “No space left on device” despite free bytes).
df -i
# Linux & macOS: shows inode usage by filesystem
  • Programmatic “free bytes” for current mount (Linux GNU coreutils).
df --output=avail -k . | tail -1
# Prints available KB on the current filesystem; GNU df only

Things to Consider

  • Commands are largely POSIX; df and du work on Linux and macOS. Flags differ: df -T is Linux-only. macOS equivalents use diskutil.
  • “Folders” are called directories in POSIX systems and man pages.
  • Units: -h uses powers of 1024; some tools also support -H (1000). Be consistent when comparing outputs.
  • Permissions can hide usage. Use sudo when needed to traverse protected paths with du.
  • Network mounts, containers, and snapshots can skew numbers. Confirm mount points and storage layers before acting.

IMPORTANT: You need to use the /dev prefix when referencing devices, like sda1 or nvme0n1p1, due to how Linux organizes device files and how the system interacts with them.

Understanding Device Files

  1. Device Files in /dev: In Linux, all hardware devices are represented as files in the /dev directory. These files are known as device files. For example, /dev/sda1 represents the first partition on the first SATA hard drive, and /dev/nvme0n1p1 represents the first partition on an NVMe drive.

  2. lsblk Output: The lsblk command lists block devices in a more user-friendly format, showing the device names without the /dev prefix. This is simply for readability. When you see sda1 in the output of lsblk, it refers to the same device as /dev/sda1.

Why the Prefix is Necessary

  • Command Context: When you use commands like mount, df, or du, they require the full path to the device file in /dev to interact with the actual hardware. The system needs to know exactly where to find the device file in the filesystem hierarchy.

  • File System Hierarchy: The Linux filesystem is organized in a hierarchical structure, and /dev is a standard directory that contains device files. Without the prefix, the system would not know where to look for the device.

While lsblk provides a simplified view of devices, the /dev prefix is necessary for commands that interact with those devices directly. Always use the full path when referencing device files in commands to ensure proper functionality.

When you specify /dev/sda2, you’re pointing to a device file, not a directory containing files. The du command does not operate on block devices directly; it needs to access the filesystem mounted on that device to calculate usage.

Check out this full example:

$ df
Filesystem     1K-blocks     Used Available Use% Mounted on
tmpfs            1216548     1512   1215036   1% /run
efivarfs             128       14       110  11% /sys/firmware/efi/efivars
/dev/sda2      479079112 23354852 431314868   6% /
tmpfs            6082724        0   6082724   0% /dev/shm
tmpfs               5120       16      5104   1% /run/lock
/dev/nvme0n1p1     98304    33990     64314  35% /boot/efi
tmpfs            1216544      176   1216368   1% /run/user/1000

$ du /dev/sda2
0	/dev/sda2

$ du -h /dev/sda2
0	/dev/sda2

$ df -h
Filesystem      Size  Used Avail Use% Mounted on
tmpfs           1.2G  1.5M  1.2G   1% /run
efivarfs        128K   14K  110K  11% /sys/firmware/efi/efivars
/dev/sda2       457G   23G  412G   6% /
tmpfs           5.9G     0  5.9G   0% /dev/shm
tmpfs           5.0M   16K  5.0M   1% /run/lock
/dev/nvme0n1p1   96M   34M   63M  35% /boot/efi
tmpfs           1.2G  176K  1.2G   1% /run/user/1000

Gotchas

  • Hidden entries aren’t shown by du -sh /dir/*. Consider also checking dotfiles.
  • df -h shows filesystem usage, not per-directory detail. Use du for directory totals.
  • Mixing Linux flags on macOS (e.g., df -T) fails. Use diskutil on macOS for disk details.
  • “No space left on device” can be inode exhaustion. Check with df -i.
  • Deleting open files won’t immediately free space. Restart the holding process or the system; on Linux, lsof | grep deleted can help.
  • Running sudo rm -rf to free space is risky. Verify paths first; prefer targeted deletes.
  • Using du on device files (e.g., /dev/sda2) returns 0 since it counts files—not block devices. Use df for filesystem usage instead.

NOTE:df -i displays inode usage, showing the total, used, and free inodes on a filesystem, which is crucial for managing files, especially when dealing with many small files. In contrast, df -h provides human-readable disk space usage, indicating the total size, used space, and available space on the filesystem.

$ df -i
Filesystem       Inodes  IUsed    IFree IUse% Mounted on
tmpfs           1520681    974  1519707    1% /run
efivarfs              0      0        0     - /sys/firmware/efi/efivars
/dev/sda2      30498816 523759 29975057    2% /
tmpfs           1520681      1  1520680    1% /dev/shm
tmpfs           1520681      7  1520674    1% /run/lock
/dev/nvme0n1p1        0      0        0     - /boot/efi
tmpfs            304136    132   304004    1% /run/user/1000

Sources


Further Investigation

  • Interactive usage viewer: ncdu (sudo apt install ncdu, brew install ncdu).
  • File system features and quotas: ext4/xfs/btrfs/zfs docs.
  • macOS APFS snapshots can occupy space; see tmutil listlocalsnapshots /.
  • GNU Coreutils Manual on Free Space Usage in Linux

TL;DR

Here’s the Linux check disk space summary.

  • List disks:
lsblk -f        # Linux
diskutil list   # macOS
  • Overall free space:
df -h
  • Current mount only:
df -h .
  • Largest subfolders (top level):
du -sh /path/* | sort -h