The df command in Linux: how to view available disk space

Introduction to the df command

The df command (short for disk free) is a fundamental tool in any Linux distribution that allows you to quickly obtain information about the usage of space on mounted filesystems. Its output shows, for each mount point, the total size, used space, free space, and utilization percentage. This information is essential for system administrators, developers, and any user who needs to monitor storage capacity and avoid surprises such as a full disk that could interrupt services or cause write failures.

Basic syntax

The simplest way to run df is to just type df in the terminal. Without options, the command displays information in 1‑kilobyte blocks, which can be hard to read on large disks. To make the output more friendly you usually add the -h (human‑readable) option, which converts the numbers to units like K, M, G as needed. Likewise, you can specify one or more filesystems or mount points as arguments to limit the query to specific devices.

Most used options

  • -h: shows sizes in a readable format (KB, MB, GB).
  • -T: includes the filesystem type (ext4, xfs, btrfs, etc.) in an additional column.
  • -a: shows all filesystems, including those with zero size or pseudo‑filesystems such as proc, sysfs, and tmpfs.
  • -i: instead of disk space, shows inode usage, useful for detecting exhaustion of file structures.
  • -t : filters the output to include only filesystems of the specified type.
  • -x : excludes filesystems of the indicated type.

Practical examples

  • View the usage of all disks in readable format: df -h

  • Include the filesystem type: df -hT

  • Show only ext4 filesystems: df -h -t ext4

  • Exclude tmpfs filesystems (useful to ignore virtual memory): df -h -x tmpfs

  • Check inode usage on the root partition: df -i /

  • Obtain information for a specific mount point, for example /home: df -h /home

Interpreting the output

Each column of df’s output has a concrete meaning. The first column indicates the device name or filesystem (e.g., /dev/sda1). The second shows the total size of the filesystem. The third indicates the space already used. The fourth shows the space available for writing. The fifth column percentage represents the proportion of used space relative to the total. When using the -T option, an additional column appears with the filesystem type, helping you quickly identify whether you are working with ext4, xfs, btrfs, nfs, etc. If you use -i, the size columns are replaced by the total number of inodes, used inodes, free inodes, and their usage percentage.

Tips and tricks

  • Combine df with other commands via pipes to filter results, for example df -h | grep '/dev/sd' to show only physical disks.
  • Use the command watch df -h to observe in real time how disk usage varies while running an I/O‑intensive task.
  • In administration scripts, check the usage percentage and trigger alerts when it exceeds a threshold (e.g., 90 %) using constructions like df -h / | awk 'NR==2 {print $5}' and comparing the numeric value.
  • Remember that filesystems mounted read‑only will show used space but will not allow writing; df will still report free space according to the total capacity.
  • In containers or virtualization environments, df may show the host’s filesystem information; to see the container’s internal space use specific tools like docker system df.

Conclusion

The df command is one of those simple yet powerful utilities that are part of the daily routine of any Linux user. Knowing its syntax, its most common options, and how to interpret its output allows you to efficiently manage disk space, prevent capacity problems, and make informed decisions about cleaning, expanding, or reconfiguring storage systems. Practicing with the examples presented and exploring the help pages (man df) will solidify your mastery of this essential tool.

This post is also available in ESPAÑOL.

Esta obra está bajo una Licencia Creative Commons Atribución 4.0 Internacional para Francesc Roig francesc@vivaldi.net .