Master the Linux ‘df’ Command: A Comprehensive Guide

Peter Hou
3 min readJun 9, 2023

--

This article provides an in-depth guide to the Linux ‘df’ command. Covering everything from its history, through its usage and common parameters, to more advanced techniques and common use cases, this guide should provide beginners with the knowledge they need to use the ‘df’ command effectively.

Instructions

This guide is designed to provide an in-depth understanding of the Linux ‘df’ command. It covers the history, usage, parameters, and most common use cases of the command. Additionally, this guide includes details to be aware of when using the ‘df’ command, as well as unusual usage techniques.

History

The ‘df’ command, short for “disk free,” has been a part of UNIX and Unix-like operating systems since their early days. It was designed as a tool for monitoring the amount of disk space used and available on a system.

When and why to use it

The ‘df’ command is primarily used when you need to check the amount of disk space used and available on your filesystems. This can be especially important when managing server systems, where running out of disk space can lead to significant problems.

How to use it

Using ‘df’ is straightforward. Running the command without any options will display the disk usage of all mounted filesystems.

$ df
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/sda1 102384432 45735432 51335636 47% /
tmpfs 4145120 4 4145116 1% /dev/shm

The commonly used parameters

  • -h Displays disk space in human-readable format (i.e., bytes, kilobytes, megabytes, gigabytes).
$ df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda1 98G 44G 49G 47% /
tmpfs 4.0G 4.0K 4.0G 1% /dev/shm
  • -T Displays the type of the filesystem.
$ df -T
Filesystem Type 1K-blocks Used Available Use% Mounted on
/dev/sda1 ext4 102384432 45735432 51335636 47% /
tmpfs tmpfs 4145120 4 4145116 1% /dev/shm

Other supported parameters

  • -a Includes filesystems with 0 blocks in the output.
  • -i Displays inode information instead of block usage.
  • -x Excludes filesystems of the specified type.
  • -l Limits the output to local filesystems only.

Most common use cases

The most common use case for the ‘df’ command is monitoring disk usage in server environments, especially in situations where resources are limited.

$ df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda1 98G 44G 49G 47% /
tmpfs 4.0G 4.0K 4.0G 1% /dev/shm

The tricky skills

It can be useful to combine ‘df’ with other commands. For example, you can sort the output by disk usage using the ‘sort’ command.

$ df --output=size,target | sort -n -r
Size Mounted on
98G /
4.0G /dev/shm

What needs to be noted

  1. Disk usage reported by ‘df’ may not reflect recent changes due to caching.
  2. The ‘df’ command reports disk space usage for the entire filesystem, not individual directories.

Conclusion

The ‘df’ command is an essential tool for managing and monitoring disk usage in Linux. It provides administrators with quick access to information about filesystem usage, helping them to manage resources effectively.

--

--

Peter Hou
Peter Hou

Written by Peter Hou

I am a Senior Software Engineer and tech lead in a top tech company.

No responses yet