Americas

  • United States
sandra_henrystocker
Unix Dweeb

Using the df command on Linux

How-To
Jan 23, 20245 mins
Linux

The Linux df command provides a lot of useful information on file system usage.

Profile photo of a developer / programmer reviewing code on monitors in his workspace.
Credit: Roman Samborskyi / Shutterstock

The df command provides information on file system usage, but includes quite a few options. This post examines the differences and makes some suggestions about when you should use which of the two commands.

The df command stands for “disk free” and, as that name suggests, it focuses on how much free disk space is available with a clear report like this one:

$ df
Filesystem     1K-blocks    Used Available Use% Mounted on
devtmpfs            4096       0      4096   0% /dev
tmpfs            1939948       0   1939948   0% /dev/shm
tmpfs             775980    1688    774292   1% /run
efivarfs              64      11        48  19% /sys/firmware/efi/efivars
/dev/sda3       13974528 7045364   6330668  53% /
tmpfs            1939948      16   1939932   1% /tmp
/dev/sda3       13974528 7045364   6330668  53% /home
/dev/sda2         996780  305840    622128  33% /boot
/dev/sda1         613160   17780    595380   3% /boot/efi
tmpfs             387988     128    387860   1% /run/user/1000
tmpfs             387988      40    387948   1% /run/user/1001

The default, as you can see from the above output, reports in one kilobyte blocks (1,024 bytes per block) and all file systems are listed. You can ask the command to report on a single file system like this:

$ df /dev/sda3
Filesystem     1K-blocks    Used Available Use% Mounted on
/dev/sda3       13974528 7044600   6331272  53% /

You can also request the information by the name of the mount point. This might make the command a tad easier.

$ df /home
Filesystem     1K-blocks    Used Available Use% Mounted on
/dev/sda3       13974528 7044600   6331272  53% /home

One of the nicest options for this command is to request the data you want to see in a human-friendly format. This would be analogous to telling your old friend that you’re about to celebrate your 17th anniversary, you expect to take two weeks off to celebrate, and you’ll be driving 7 hours to get to the resort where you plan to stay. Reporting all these events in the same unit of time unit would be much harder to communicate. Here’s an example of the report shown above in the human-readable format:

$ df -h
Filesystem      Size  Used Avail Use% Mounted on
devtmpfs        4.0M     0  4.0M   0% /dev
tmpfs           1.9G     0  1.9G   0% /dev/shm
tmpfs           758M  1.7M  757M   1% /run
efivarfs         64K   11K   48K  19% /sys/firmware/efi/efivars
/dev/sda3        14G  6.8G  6.1G  53% /
tmpfs           1.9G   16K  1.9G   1% /tmp
/dev/sda3        14G  6.8G  6.1G  53% /home
/dev/sda2       974M  299M  608M  33% /boot
/dev/sda1       599M   18M  582M   3% /boot/efi
tmpfs           379M  128K  379M   1% /run/user/1000
tmpfs           379M   40K  379M   1% /run/user/1001

The df command also provides some other useful options. To report on file system type, for example, you can run a command like this one:

$ df -T
Filesystem     Type     1K-blocks    Used Available Use% Mounted on
devtmpfs       devtmpfs      4096       0      4096   0% /dev
tmpfs          tmpfs      1939948       0   1939948   0% /dev/shm
tmpfs          tmpfs       775980    1680    774300   1% /run
efivarfs       efivarfs        64      11        48  19% /sys/firmware/efi/efivars
/dev/sda3      btrfs     13974528 7044600   6331272  53% /
tmpfs          tmpfs      1939948      16   1939932   1% /tmp
/dev/sda3      btrfs     13974528 7044600   6331272  53% /home
/dev/sda2      ext4        996780  305840    622128  33% /boot
/dev/sda1      vfat        613160   17780    595380   3% /boot/efi
tmpfs          tmpfs       387988     128    387860   1% /run/user/1000
tmpfs          tmpfs       387988      40    387948   1% /run/user/1001

The command below focuses on the btrfs file systems only:

$ df -t btrfs
Filesystem     1K-blocks    Used Available Use% Mounted on
/dev/sda3       13974528 7043212   6332692  53% /
/dev/sda3       13974528 7043212   6332692  53% /home

Alternatively, if you simply want to report on inodes (those little data structures that describe file-system objects such as file and directories on Linux systems), you can use a command like this:

$ df -i
Filesystem      Inodes IUsed   IFree IUse% Mounted on
devtmpfs        479307   544  478763    1% /dev
tmpfs           484987     2  484985    1% /dev/shm
tmpfs           819200  1077  818123    1% /run
efivarfs             0     0       0     - /sys/firmware/efi/efivars
/dev/sda3            0     0       0     - /
tmpfs          1048576    51 1048525    1% /tmp
/dev/sda3            0     0       0     - /home
/dev/sda2        65536    43   65493    1% /boot
/dev/sda1            0     0       0     - /boot/efi
tmpfs            96997   154   96843    1% /run/user/1000
tmpfs            96997    44   96953    1% /run/user/1001

Note that in the output above, user files are mounted in /run/user. You can focus on a single file system or partition with a command like this:

$ df -i /boot
Filesystem     Inodes IUsed IFree IUse% Mounted on
/dev/sda2       65536    43 65493    1% /boot

If you use the -a option with the df command, you might be in for a surprise. It will include include pseudo, duplicate and even inaccessible file systems in its output. The example below shows only the top portion of the amount of output you’re likely to see.

$ df -a | head -11
Filesystem     1K-blocks    Used Available Use% Mounted on
proc                   0       0         0    - /proc
sysfs                  0       0         0    - /sys
devtmpfs            4096       0      4096   0% /dev
securityfs             0       0         0    - /sys/kernel/security
tmpfs            1939948       0   1939948   0% /dev/shm
devpts                 0       0         0    - /dev/pts
tmpfs             775980    1676    774304   1% /run
cgroup2                0       0         0    - /sys/fs/cgroup
pstore                 0       0         0    - /sys/fs/pstore
efivarfs              64      11        48  19% /sys/firmware/efi/efivars

That’s less than one third of the total output available. Here’s a command that will count the lines in the full command output:

$ df -a | wc -l
36

Wrap-up

The df (disk free) command is very useful for examining your file system space usage – something you ought to do from time to time to ensure that you’re not running short of needed disk space.

sandra_henrystocker
Unix Dweeb

Sandra Henry-Stocker has been administering Unix systems for more than 30 years. She describes herself as "USL" (Unix as a second language) but remembers enough English to write books and buy groceries. She lives in the mountains in Virginia where, when not working with or writing about Unix, she's chasing the bears away from her bird feeders.

The opinions expressed in this blog are those of Sandra Henry-Stocker and do not necessarily represent those of IDG Communications, Inc., its parent, subsidiary or affiliated companies.

More from this author