Bash Disk Space

Learn how to inspect filesystem space usage on Linux with the df command, and how the -h flag turns raw byte counts into readable sizes.

What df Shows You

The df command, short for disk free, reports how much space is used and available on every mounted filesystem. It reads live numbers from the kernel, so the report is always current, with no need to manually total up file sizes yourself.

Example

$ df
Filesystem     1K-blocks     Used Available Use% Mounted on
/dev/sda1       61255492 24681320  33447800  43% /
tmpfs            4051928        0   4051928   0% /dev/shm
/dev/sdb1      103080224 87213056  10552736  90% /data

By default the 1K-blocks, Used, and Available columns are printed in kilobytes. That is precise but hard to read at a glance, since nobody wants to mentally convert 61255492 into gigabytes. This is exactly the problem the -h flag solves.

Example

$ df -h
Filesystem      Size  Used Avail Use% Mounted on
/dev/sda1        59G   24G   32G  43% /
tmpfs           3.9G     0  3.9G   0% /dev/shm
/dev/sdb1        99G   84G   11G  90% /data

Narrowing Down and Adding Detail

You rarely need every filesystem on the machine at once. Pass a specific path to df and it reports only the filesystem that path lives on. Add -T to include a Type column showing ext4, xfs, tmpfs, and similar, which is handy when a mount behaves oddly and you want to confirm what kind of filesystem it actually is.

Example

$ df -hT /data
Filesystem     Type  Size  Used Avail Use% Mounted on
/dev/sdb1      ext4   99G   84G   11G  90% /data
  • -h prints sizes in human-readable K/M/G/T units
  • -T shows the filesystem type column
  • -i reports inode counts instead of byte space
  • --total prints a combined grand total row
  • -a includes pseudo filesystems like proc that are normally hidden
FlagDescription
-hPrint sizes in human-readable units instead of 1K blocks
-TShow the filesystem type, such as ext4, xfs, or tmpfs
-iReport inode usage instead of block usage
--totalPrint a grand total line at the bottom of the report
-aInclude filesystems normally omitted, such as proc and tmpfs
Note: Pipe df -h through grep to check one mount instantly, for example df -h | grep data, instead of scanning the whole table.
Note: Once Use% reaches 100%, writes to that filesystem start failing with No space left on device. Treat 90% and above as an active warning, not just full as the failure line.