How to Check Disk Space Usage with the df Command

Using the Linux df command

It’s important to always be aware of resource usage in your cloud VPS. Without a cPanel or other graphical user interfaces (GUIs) you need how to monitor your system on the command line. This is not difficult, and actually many users prefer to work this way. Once you get used to it, command line work can be fun and time-saving.

The most common utility used in measuring disk space is the GNU df command, which is already installed in your system. In this article, we will go through the basic usage of this command as well as provide you with the advanced options, so this article can serve as your singular resource for everything you ever wanted to know about the df command.

Using The df Command

For more information check out the GNU website.

One of the best ways to check for free disk space is to use the df (disk free) command.

The GNU df command prints out to you all of the available disk space on your file system for each “file” (remember that drives are mounted as device “files” in Unix-like systems).

For more information on how disks are mounted (or not mounted) on your system, see the below section of disk mounting and file system.

The Basic Usage

Most basically, it is recommended to use the df command with the -h (human readable) option, to convert the bytes into easily readable megabyte and gigabyte measurements.

Here’s the command with the -h output from an Ubuntu system:

df -h
Filesystem      Size  Used Avail Use% Mounted on
udev            3.7G     0  3.7G   0% /dev
tmpfs           776M  4.2M  772M   1% /run
/dev/mmcblk0p2   30G   15G   15G  51% /
tmpfs           3.8G     0  3.8G   0% /dev/shm
tmpfs           5.0M     0  5.0M   0% /run/lock
tmpfs           3.8G     0  3.8G   0% /sys/fs/cgroup
/dev/loop0       49M   49M     0 100% /snap/core18/1936
/dev/loop2       49M   49M     0 100% /snap/core18/2002
/dev/loop1       29M   29M     0 100% /snap/snapd/11584
/dev/loop4      128K  128K     0 100% /snap/software-boutique/56
/dev/loop5      128K  128K     0 100% /snap/ubuntu-mate-pi/11
/dev/loop3       27M   27M     0 100% /snap/snapd/9730
/dev/loop6       16M   16M     0 100% /snap/ubuntu-mate-welcome/615
/dev/loop7       16M   16M     0 100% /snap/ubuntu-mate-welcome/625
/dev/mmcblk0p1  255M  119M  137M  47% /boot/firmware
tmpfs           776M   52K  776M   1% /run/user/1000

For demonstration purposes, here is the raw output without the -h option:

df
Filesystem     1K-blocks     Used Available Use% Mounted on
udev             3826036        0   3826036   0% /dev
tmpfs             794560     4244    790316   1% /run
/dev/mmcblk0p2  30448324 15300444  15131496  51% /
tmpfs            3972792        0   3972792   0% /dev/shm
tmpfs               5120        0      5120   0% /run/lock
tmpfs            3972792        0   3972792   0% /sys/fs/cgroup
/dev/loop0         50048    50048         0 100% /snap/core18/1936
/dev/loop2         50176    50176         0 100% /snap/core18/2002
/dev/loop1         28800    28800         0 100% /snap/snapd/11584
/dev/loop4           128      128         0 100% /snap/software-boutique/56
/dev/loop5           128      128         0 100% /snap/ubuntu-mate-pi/11
/dev/loop3         27520    27520         0 100% /snap/snapd/9730
/dev/loop6         15616    15616         0 100% /snap/ubuntu-mate-welcome/615
/dev/loop7         15616    15616         0 100% /snap/ubuntu-mate-welcome/625
/dev/mmcblk0p1    260968   121336    139632  47% /boot/firmware
tmpfs             794556       52    794504   1% /run/user/1000

Complete Option Layout

-a, -all
include psuedo, duplicate, and inaccessible file systems
-B, --block-size=SIZE
scale sizes by parameter “SIZE”
-h, --human-readable
print size in powers of 1024 (basically formatted as megabyte or gigabyte)
-H, --si
print sizes in powers of 1000 (e.g., 1.1G)
-i, --inodes
list inode information instead of block usage
-k
like –block-size=1K
-l, --local
limit listing to local file systems
--no-sync
do not invoke sync before getting usage info (default)
--output[=FIELD_LIST]
use the output format defined by the FIELDLIST parameter, or print all fields if parameter is omitted.
-P, --portability
use the POSIX output format
--sync
invoke sync before getting usage info
--total
elide all entries insignificant to available space, and produce a grand total
-t, --type=TYPE
limit listing to file systems of type “TYPE”
-T, --print-type
print file system type
-x, --exclude-type=TYPE
limit listing to file systems not of type “TYPE”
-v
(ignored)
--help
display this help and exit
--version
output version information and exit

Disk Mounting and File System

In the classical Unix-like file system, you can mount drives to a location in the file system. This may seem foreign to you if you are accustomed to how your operating system automatically mounts a drive to a convenient location the same way each time. But if you think about it, the mounting system offers you some more flexibility. For example, if you want to mount a drive to /USB/drive/, you can use that path, and no matter what drive you mount there, the path will stay the same. This gives you some flexibility in writing scripts, managing backups, or a whole host of other important system tasks.

What Are Blocks and Block Size?

Programs like df display disk sizes in blocks. As you saw in the above output examples, the default block size is measured in bytes. But this can be difficult to calculate on the spot with respect to how much this space this means to you. So you can specify your byte usage by having the computer calculate by blocks of various sizes. For example, in the df -h command, the output of bytes (the blocks, basically) are automatically re-calculated to give you the measurements in powers 1,024 bytes. This most closely approximates gigbytes, megabytes, and kilobytes you’re accustomed to seeing in your operating system.

More Resources on System Monitoring

Check out these other resources from the support center:

CM
Christopher Maiorana Content Writer II

Christopher Maiorana joined the InMotion community team in 2015 and regularly dispenses tips and tricks in the Support Center, Community Q&A, and the InMotion Hosting Blog.

More Articles by Christopher

Was this article helpful? Join the conversation!

Questions about our MailChannels Deployment? We have answers and are here to help!Learn More
+