Skip to main content

4 tips to help you get the most out of the Linux df command

Take another look at df and learn its secrets.
Image
Files

A few months back, I wrote a quick comparison piece between the well known du and df commands. That first piece left a lot on the table about the different practical uses for each command and led me to write standalone pieces for each. I have already covered the du command in greater detail, so this is df's day in the sun.

df stands for "disk free" (I have also seen it referred to as "disk filesystem"). It is a *nix command that allows the user to display the available disk space on a given filesystem. As we know, many Linux commands are not super useful in their vanilla form, so let's look at how to spice up the df command.

Vanilla (no options)

Ok, ok, I know I said we were going to spice it up. Let's first get the boring stuff out of the way. The default df command will give you something like this:

[root@rhel ~]# df
Filesystem            1K-blocks    Used Available Use% Mounted on
devtmpfs                4052684       0   4052684   0% /dev
tmpfs                   4080828       0   4080828   0% /dev/shm
tmpfs                   4080828    9720   4071108   1% /run
tmpfs                   4080828       0   4080828   0% /sys/fs/cgroup
/dev/mapper/rhel-root  27245572 7365760  19879812  28% /
/dev/sda1               1038336  308852    729484  30% /boot
tmpfs                    816164    1180    814984   1% /run/user/42
tmpfs                    816164    6952    809212   1% /run/user/1000

This output isn't overly reader-friendly, and honestly, other than the percentages, it doesn't give me much info that I am going to care about. I don't want to do a byte conversion on every value. Ok, now we can spice it up.

Display all

This option does exactly what it says. Use the -a flag to display all filesystems. Note that this output is rather lengthy, depending on the size of your system.

[root@rhel ~]# df -a
Filesystem            1K-blocks    Used Available Use% Mounted on
sysfs                         0       0         0    - /sys
proc                          0       0         0    - /proc
devtmpfs                4052684       0   4052684   0% /dev
securityfs                    0       0         0    - /sys/kernel/security
tmpfs                   4080828       0   4080828   0% /dev/shm
devpts                        0       0         0    - /dev/pts
tmpfs                   4080828    9716   4071112   1% /run
tmpfs                   4080828       0   4080828   0% /sys/fs/cgroup
cgroup                        0       0         0    - /sys/fs/cgroup/systemd
pstore                        0       0         0    - /sys/fs/pstore
bpf                           0       0         0    - /sys/fs/bpf
cgroup                        0       0         0    - /sys/fs/cgroup/rdma
cgroup                        0       0         0    - /sys/fs/cgroup/freezer
cgroup                        0       0         0    - /sys/fs/cgroup/pids
cgroup                        0       0         0    - /sys/fs/cgroup/perf_event
cgroup                        0       0         0    - /sys/fs/cgroup/net_cls,net_prio
cgroup                        0       0         0    - /sys/fs/cgroup/devices
cgroup                        0       0         0    - /sys/fs/cgroup/blkio
cgroup                        0       0         0    - /sys/fs/cgroup/cpu,cpuacct
cgroup                        0       0         0    - /sys/fs/cgroup/cpuset
cgroup                        0       0         0    - /sys/fs/cgroup/memory
cgroup                        0       0         0    - /sys/fs/cgroup/hugetlb
configfs                      0       0         0    - /sys/kernel/config
/dev/mapper/rhel-root  27245572 7365752  19879820  28% /
selinuxfs                     0       0         0    - /sys/fs/selinux
hugetlbfs                     0       0         0    - /dev/hugepages
systemd-1                     -       -         -    - /proc/sys/fs/binfmt_misc
debugfs                       0       0         0    - /sys/kernel/debug
mqueue                        0       0         0    - /dev/mqueue
/dev/sda1               1038336  308852    729484  30% /boot
sunrpc                        0       0         0    - /var/lib/nfs/rpc_pipefs
tmpfs                    816164    1180    814984   1% /run/user/42
tmpfs                    816164    6952    809212   1% /run/user/1000
fusectl                       0       0         0    - /sys/fs/fuse/connections
gvfsd-fuse                    0       0         0    - /run/user/1000/gvfs
binfmt_misc                   0       0         0    - /proc/sys/fs/binfmt_misc

Again, other than the percentages, nothing jumps out at me here. Let's look at some options to make this more enjoyable for human eyes.

For human consumption

Now we are getting to the useful stuff. To change the output to a human-readable format, use the -h flag. This option displays values like 5K, 10M, 15G, etc.

[root@rhel ~]# df -h
Filesystem             Size  Used Avail Use% Mounted on
devtmpfs               3.9G     0  3.9G   0% /dev
tmpfs                  3.9G     0  3.9G   0% /dev/shm
tmpfs                  3.9G  9.5M  3.9G   1% /run
tmpfs                  3.9G     0  3.9G   0% /sys/fs/cgroup
/dev/mapper/rhel-root   26G  7.1G   19G  28% /
/dev/sda1             1014M  302M  713M  30% /boot
tmpfs                  798M  1.2M  796M   1% /run/user/42
tmpfs                  798M  6.8M  791M   1% /run/user/1000

Much better, yes? Now let's look at how to break down the data in specific units of measure.

Mega

To view the output of your filesystem in everyone's favorite value, Megabytes, use the -m option.

[root@rhel ~]# df -m
Filesystem            1M-blocks  Used Available Use% Mounted on
devtmpfs                   3958     0      3958   0% /dev
tmpfs                      3986     0      3986   0% /dev/shm
tmpfs                      3986    10      3976   1% /run
tmpfs                      3986     0      3986   0% /sys/fs/cgroup
/dev/mapper/rhel-root     26608  7194     19414  28% /
/dev/sda1                  1014   302       713  30% /boot
tmpfs                       798     2       796   1% /run/user/42
tmpfs                       798     7       791   1% /run/user/1000

To view the output of your command in large bills (Gigabytes), use the human-readable option -h, and, for those of you who like to use bytes, use the default command or the -k option for 1K block size.

Filesystem specifics

On some systems, you may have multiple types of filesystem active. To view the output and the associated filesystem type, use the -T option.

[root@rhel ~]# df -T
Filesystem            Type     1K-blocks    Used Available Use% Mounted on
devtmpfs              devtmpfs   4052684       0   4052684   0% /dev
tmpfs                 tmpfs      4080828       0   4080828   0% /dev/shm
tmpfs                 tmpfs      4080828    9720   4071108   1% /run
tmpfs                 tmpfs      4080828       0   4080828   0% /sys/fs/cgroup
/dev/mapper/rhel-root xfs       27245572 7365948  19879624  28% /
/dev/sda1             xfs        1038336  308852    729484  30% /boot
tmpfs                 tmpfs       816164    1180    814984   1% /run/user/42
tmpfs                 tmpfs       816164    6952    809212   1% /run/user/1000

You can include/exclude by filesystem type as well. To include a certain filesystem type (XFS in this example), we use the following:

[root@rhel ~]# df -t xfs
Filesystem            1K-blocks    Used Available Use% Mounted on
/dev/mapper/rhel-root  27245572 7365928  19879644  28% /
/dev/sda1               1038336  308852    729484  30% /boot

To exclude a certain filesystem type (XFS again), use the following:

[root@rhel ~]# df -x xfs
Filesystem     1K-blocks  Used Available Use% Mounted on
devtmpfs         4052684     0   4052684   0% /dev
tmpfs            4080828     0   4080828   0% /dev/shm
tmpfs            4080828  9716   4071112   1% /run
tmpfs            4080828     0   4080828   0% /sys/fs/cgroup
tmpfs             816164  1180    814984   1% /run/user/42
tmpfs             816164  6952    809212   1% /run/user/1000

30,000 feet

As you can see from the options presented, the df command has more than enough to get you a bird's eye view. As with all Linux commands, there are more options available than I care to cover here, so if you want a full look at them, check out the man page by running man df on your system. In the real world, df is often paired with the du command to help you get a complete understanding of what filesystems are bloated and which directories are to blame.

For more Linux tips and tricks, keep an eye on Enable Sysadmin!

[ Free online course: Red Hat Enterprise Linux technical overview. ]

Topics:   Linux  
Author’s photo

Tyler Carrigan

Tyler is a community manager at Enable Sysadmin, a submarine veteran, and an all-round tech enthusiast! He was first introduced to Red Hat in 2012 by way of a Red Hat Enterprise Linux-based combat system inside the USS Georgia Missile Control Center. More about me

Related Content

OUR BEST CONTENT, DELIVERED TO YOUR INBOX