Home / Alt manpages / df(1)

  • df(1)
  • User command
  • linux

Check Disk Space and Inodes with df

Something just failed with "No space left on device" and you need to know which file system is actually full. df answers that in seconds, and it is read-only.

This guide covers four questions: which file system holds a path, how much space is left, whether inodes are running out, and how to get stable columns for scripts. Allow about ten minutes. No elevated privileges are normally needed.

Tip

Jump to the numbered section that matches your question. The checklist at the end confirms you got a trustworthy answer.

1. Confirm the installed command

This guide uses GNU df from coreutils 9.4, installed here as package version 9.4-3ubuntu6.3. Check your own host before relying on version-specific output:

$ command -v df
/usr/bin/df
$ df --version | sed -n '1p'
df (GNU coreutils) 9.4

df reports space on the mounted file system containing each path. With no path, it reports the mounted file systems it can see. It cannot work out usage for an unmounted file system from a device name alone.

2. Check the file system behind a path

Give df a directory or file when you care about one location. -h uses powers of 1024 and picks compact units such as M and G:

$ df -h /tmp
Filesystem      Size  Used Avail Use% Mounted on
/dev/md2        3.6T  710G  2.7T  21% /

Your numbers will differ and they shift as files come and go. Read the columns left to right:

  • Size. Total capacity.
  • Used. Allocated space.
  • Avail. Space available to ordinary users.
  • Use%. Percentage used.
  • Mounted on. The mount point.

A path such as /tmp reports the root file system if it is not a separate mount. To compare locations, check several paths in one go:

$ df -h /var/log /home

Look for differences in the Filesystem or Mounted on columns. This is a lookup only. df does not say which directory ate the space, so use a separate disk-usage investigation for that.

3. Choose units deliberately

Human-readable output suits a terminal, but scripts should pick a unit explicitly. -B1 prints bytes, while -B1K, -B1M and similar scale by powers of 1024. -H uses powers of 1000 instead:

$ df -P -B1 /tmp
Filesystem          1-blocks         Used     Available Capacity Mounted on
/dev/md2       3918718345216 761662898176 2957918871552      21% /
$ df -H /tmp

-P asks for the POSIX layout, handy when another program expects one file system per line. For a stable report, prefer an explicit block size over the environment.

The environment can quietly change your numbers. GNU df also reads DF_BLOCK_SIZE, BLOCK_SIZE and BLOCKSIZE. POSIXLY_CORRECT changes the fallback from 1024-byte blocks to 512-byte blocks, so an inherited environment can make an identical-looking command print different raw values.

Inspect the relevant variables if a result looks odd:

$ env | grep -E '^(DF_BLOCK_SIZE|BLOCK_SIZE|BLOCKSIZE|POSIXLY_CORRECT)='

No output means none of them are set in the current shell.

Warning

Do not casually export a block-size variable from a shared shell profile. It changes every other command that honours the same convention.

4. Check inode exhaustion separately

A file system can have free bytes and no free inodes, and then new files cannot be created. It bites hardest with workloads that produce huge numbers of small files. -i swaps the byte-capacity columns for inode counts:

$ df -i /tmp
Filesystem        Inodes   IUsed     IFree IUse% Mounted on
/dev/md2       243073024 2764937 240308087    2% /

Compare IUse% and the remaining IFree, not the byte columns from an earlier command. A high inode percentage needs a different investigation from a full byte allocation.

Warning

Do not delete files just because an inode figure is high. Identify the affected mount first, then decide which data is safe to remove.

5. Make reports easier to parse

GNU df can select named output fields. That stops you depending on the position of optional columns, and it can include the file system type:

$ df -B1 --output=source,fstype,size,used,avail,pcent,target /tmp
Filesystem     Type     1B-blocks         Used         Avail Use% Mounted on
/dev/md2       ext4 3918718345216 761662898176 2957918871552  21% /

Valid field names in this installed version are source, fstype, itotal, iused, iavail, ipcent, size, used, avail, pcent, file and target. The header stays in the output, so a script must handle it explicitly rather than assume line one is data.

Use the exit status to detect failure. A missing path, an unreadable mount table or an invalid option can leave you with an unusable result:

$ df -h /path/to/check
$ printf 'df exit status: %s\n' "$?"
df exit status: 0

Replace the path with a real location before copying the command. A non-zero status is a diagnostic, not proof that the file system is full.

6. Avoid misleading or disruptive checks

By default this GNU build uses --no-sync, so it does not call sync before reading usage data. --sync asks the system to flush pending writes first.

Warning

--sync can add delay and disk activity. Keep it for a specific reason, and do not treat it as a harmless freshness switch on a busy host.

Options such as -a include pseudo, duplicate and inaccessible file systems, which makes a full inventory far noisier than the default. Narrow things down like this:

  • -T shows the file system type.
  • -l limits the report to local file systems.
  • -t TYPE and -x TYPE include or exclude a known type.

Verify the type first:

$ df -T /tmp
Filesystem     Type  1024-blocks      Used Available Capacity Mounted on
/dev/md2       ext4    3826873384 743811424 2888592648      21% /

Do not reach for sudo as a reflex. Reading ordinary mounted file-system statistics is normally unprivileged. If one mount is inaccessible, look into its permissions and mount state instead of assuming elevated access will make an incomplete report accurate.

Done means

  • Right file system. You checked the one containing the path that matters, rather than assuming its mount point.
  • Units chosen. You picked -h, -H or an explicit -B unit to suit the audience and purpose.
  • Inodes ruled in or out. You ran -i when a file-creation failure could be inode exhaustion.
  • Scripts hardened. They use selected fields, an explicit unit and the exit status.
  • Side effects known. --sync can cause extra write activity, and -a can add pseudo or duplicate mounts.