How to Check Disk Space in Linux with the df Command

How to Check Disk Space in Linux with the df Command

df -h /var can show the filesystem mounted at /, not a size for /var itself. I’m intrigued by how a path can lead to a mount’s space report instead of a directory total.

You’ll get a clear sense of what each capacity column measures. Turn to df’s report and read its capacity figures alongside the filesystem entries.

What df reports

The df command reports storage counters for mounted filesystems, so it answers a different question from a directory walk with du.

With no file argument, GNU df lists mounted filesystems. A file or path argument selects its containing filesystem, and Mounted on names the directory where it appears.

ColumnWhat it reports
FilesystemThe device or filesystem name reported by the mount.
SizeTotal capacity shown in the selected units.
UsedBlocks the filesystem reports as used.
AvailSpace available to users, which can exclude reserved blocks.
Use%df’s rounded percentage for used space.
Mounted onThe directory where that filesystem appears.
TypeFilesystem type, shown when you add -T.

Use our guide to disk partitioning tools for Linux when you need the device and partition layout.

Read the units before comparing values

GNU df defaults to 1K blocks unless a block-size environment setting changes them. POSIXLY_CORRECT changes the fallback unit to 512 bytes, so check df’s help text when scripts or shell settings might affect the display.

  • -h displays rounded sizes in 1024-based units, such as M or G.
  • -H uses 1000-based units, which can make the same capacity look different.

The GNU Coreutils df manual documents the size settings and output options. Our guide to reading Linux man pages helps you navigate the manual for your installed command.

Check mounted space with df

Start with all mounted filesystems, then switch to rounded units if block counts are hard to scan.

1. List mounted filesystems

Run df without an argument to list mounted filesystems. The default output uses 1K blocks on GNU df unless your environment overrides that unit.

df
df output listing filesystem space in 1K blocks
Example output from df

Read the Mounted on column to find the filesystem attached to a directory. Rows such as tmpfs and efivarfs describe system filesystems. Their presence doesn’t mean the machine has extra disk drives.

2. Display readable sizes

Add -h when block counts are harder to scan than rounded sizes. The Use% and Avail columns show how much space the filesystem reports as used and available.

df -h
df -h output showing readable filesystem sizes
Example output from df -h

Size, Used, and Avail may not add up exactly because filesystems reserve some blocks and df rounds displayed values. A tmpfs row is not persistent disk capacity, so don’t add it to a disk’s size.

Check the filesystem behind a path

Pass a file or directory when you want to know which filesystem contains that path. I used /var with df -h and got the filesystem mounted at /, not a size for /var itself.

df -h /var

For your path, check Mounted on in the result. A USB filesystem, for example, may be mounted at a directory beneath /media or /mnt. Our guide to mounting a USB drive on Linux explains that step.

The path argument selects the filesystem that contains it. Use du to total the directory tree itself.

Add a filesystem type or filter the list

Use -T to add a Type column, then use -t or -x to include or omit one filesystem type. The filter changes the report rows while each filesystem keeps its own capacity.

df -T /
df -T / output identifying the root filesystem as ext4
Example output from df -T /
OptionEffect
-TAdds a filesystem type column.
-t ext4Lists filesystems whose type is ext4.
-x ext4Omits filesystems whose type is ext4.
–totalAdds a total for rows included in the report.

To include only ext4 filesystems, run:

df -t ext4
df -t ext4 output limited to ext4 filesystems
Example output from df -t ext4

Use -x to leave a type out instead. The output below omits ext4 filesystems, so it won’t show an ext4 root mount.

df -x ext4
df -x ext4 output excluding ext4 filesystems
Example output from df -x ext4

For a total across the rows that df prints, add –total:

df -h --total
df -h --total output with a total row for the listed filesystems
Example output from df -h –total

The total row sums the included filesystems, including tmpfs and other system mounts when they appear. Treat it as a sum of reported rows rather than the machine’s physical-disk capacity.

The Type column identifies filesystem formats, which helps when you choose one for a device. Our Linux USB formatting guide explains that choice.

Check inode availability

Filesystems track inode availability separately from block capacity. An inode stores metadata for a file or directory, so a filesystem can have free blocks but no free inodes for new entries.

df -i /
df -i / output showing inode counts for the root filesystem
Example output from df -i /

The IFree column reports available inodes. I ran df -i / beside df -h, and their output showed the root filesystem at 9% inode use versus 52% block use.

Why df and du report different amounts

df reports filesystem counters, while du walks files and directories under a path. The two commands answer different questions, so their totals need not match.

  1. Start with scope. df counts a mounted filesystem, while du totals the directory tree you name.
  2. Check permissions. If du prints Permission denied, it cannot include the directories it could not read, and its exit status may be nonzero.
  3. Remember open deleted files. A running process can keep their blocks allocated after the directory entry disappears, so df can count space that du cannot find by walking names.

Run both tools against the same mount and let du read the directories. Our guide to listing Linux directories by size shows how to sort the output and follow a full mount into its largest directories.

A full mount needs a directory check

Once df identifies the full filesystem, inspect directories on that mount rather than adding the sizes of every filesystem row. This command lists the immediate directories under /var and stays on one filesystem.

sudo du -xhd1 /var

Use sudo only when you have permission to inspect protected paths. The df report tells you which filesystem is full, and du points to directories using its space.

Frequently asked questions about df

GNU df reports mounted filesystems, so an unmounted partition has no usage row to query yet.

Does df -h show the size of a directory?

No. df -h reports the filesystem that contains a path. Use du to total the files and directories beneath a path.

Can df check an unmounted partition?

No. GNU df reports usage for mounted filesystems. Mount the filesystem before asking df for its available space.

Is df -h different from df -H?

Yes. GNU df uses 1024-based display units with -h and 1000-based units with -H.

Why can df show more used space than du?

df reports the filesystem’s counters, while du walks reachable directory entries. Deleted files still held open by a process can remain allocated and appear in df but not in du.