Home / Alt manpages / df(1)

  • df(1)
  • User command
  • linux

Read Linux File System Capacity Clearly with df

You will use df to answer four practical questions: which file system contains a path, how much space is available, whether inodes are running out, and how to produce stable machine-readable columns. Allow about ten minutes. The commands are read-only and normally need no elevated privileges.

Checkpoint

Start at the numbered section that matches the question you need to answer. The final checklist is a quick way to confirm the result.

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 that it can see. It cannot calculate usage for an unmounted file system just from a device name.

2. Check the file system behind a path

Give df a directory or file when you care about one location. The -h option uses powers of 1024 and selects 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% /

The exact numbers depend on the machine and change as files are created. Read the columns as total capacity, allocated space, space available to ordinary users, percentage used, and mount point. A path such as /tmp can therefore report the root file system if it is not a separate mount.

Check several paths in one invocation when comparing locations:

$ df -h /var/log /home

Look for different values in the Filesystem or Mounted on columns. This is a lookup only. df does not identify which directory consumed the space; use a separate disk-usage investigation for that.

3. Choose units deliberately

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

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

-P requests the POSIX layout, useful when another program expects one file system per line. For a stable report, prefer an explicit block size over relying on the environment. 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 apparently identical command produce different raw values.

Inspect the relevant environment if a result looks inconsistent:

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

No output means those variables are not set in the current shell. Do not casually export a new block-size variable in a shared shell profile, because it changes other commands that honour the same convention.

4. Check inode exhaustion separately

A file system can have free bytes but no free inodes. That prevents new files from being created, especially in workloads that produce many small files. Use -i to replace byte-capacity columns with inode counts:

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

The important comparison is 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. Do not delete files merely because an inode figure is high: first identify the affected mount and decide which data is safe to remove.

5. Make reports easier to parse

GNU df can select named output fields. This avoids depending on the position of optional columns and 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 include source, fstype, itotal, iused, iavail, ipcent, size, used, avail, pcent, file and target. The header remains part of the output. If a script consumes the result, handle the header explicitly rather than assuming the first line is data.

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

$ 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 evidence that the file system is full.

6. Avoid misleading or disruptive checks

By default, this GNU build uses --no-sync: it does not invoke sync before reading usage data. --sync asks the system to flush pending writes first. That can add delay and disk activity, so reserve it for a specific reason and do not treat it as a harmless freshness switch in a busy host.

Options such as -a include pseudo, duplicate and inaccessible file systems. They can make a complete inventory much noisier than the default. Use -T when the file system type matters, -l to limit the report to local file systems, or -t TYPE and -x TYPE to 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 use sudo as a reflex. Reading ordinary mounted file-system statistics is normally unprivileged. If a particular mount is inaccessible, investigate its permissions and mount state rather than assuming that elevated access will make an incomplete report accurate.

Done means

  • You checked the file system containing the path that matters, rather than assuming its mount point.
  • You selected -h, -H or an explicit -B unit for the audience and purpose.
  • You checked -i when a file-creation failure could be caused by inode exhaustion.
  • Scripts use selected fields, an explicit unit and the command's exit status.
  • You know that --sync can cause extra write activity and that -a can add pseudo or duplicate mounts.