Example Usage of df Command on Linux

In today’s tutorial, we are going to learn how to use df command on Linux, df acronym for “disk free” displays the amount of disk space available on the file system containing each file name argument. If no file name is given, the space available on all currently mounted file systems is shown. Disk space is shown in 1K blocks by default.

Syntax;

df [OPTION]… [FILE]…

Example Usage of df Command on Linux

df Command By Default

When you run df command with no option and file name, it will provide a list of all of the available (already mounted) filesystems on your system, including their total size, how much space has been used, how much space is available, the usage percentage and where it is mounted.

example;

df
Filesystem     1K-blocks      Used Available Use% Mounted on
udev             3994496         0   3994496   0% /dev
tmpfs             804992      1604    803388   1% /run
/dev/sda2      180876872 115869740  55749356  68% /
tmpfs            4024948     85884   3939064   3% /dev/shm
tmpfs               5120         4      5116   1% /run/lock
tmpfs            4024948         0   4024948   0% /sys/fs/cgroup
/dev/loop0        212096    212096         0 100% /snap/code/64
/dev/loop1        212096    212096         0 100% /snap/code/65
/dev/loop3        101376    101376         0 100% /snap/core/11081
/dev/loop2        101632    101632         0 100% /snap/core/10958
/dev/loop5         56832     56832         0 100% /snap/core18/1997
/dev/loop4         56832     56832         0 100% /snap/core18/1988
/dev/loop6        223232    223232         0 100% /snap/gnome-3-34-1804/60
/dev/loop7        224256    224256         0 100% /snap/gnome-3-34-1804/66
/dev/loop8         66688     66688         0 100% /snap/gtk-common-themes/1515
/dev/loop10        52352     52352         0 100% /snap/snap-store/498
/dev/loop9         66432     66432         0 100% /snap/gtk-common-themes/1514
/dev/loop11        52352     52352         0 100% /snap/snap-store/518
tmpfs             804988        16    804972   1% /run/user/1000
/dev/sda3       83105328  75133584   3707144  96% /media/thehero/e3ef9af4-7136-4650-8365-c6c02d0d14f4
/dev/sda1      218593248  53836172 164757076  25% /media/thehero/01D5FAEEFC8E1CB0

Display Details of All Filesystem Disk Space

Use -a option to display information of all filesystem including pseudo, duplicate and inaccessible file systems.

df -a
Filesystem     1K-blocks      Used Available Use% Mounted on
sysfs                  0         0         0    - /sys
proc                   0         0         0    - /proc
udev             3994496         0   3994496   0% /dev
devpts                 0         0         0    - /dev/pts
tmpfs             804992      1600    803392   1% /run
/dev/sda2      180876872 115882228  55736868  68% /
securityfs             0         0         0    - /sys/kernel/security
tmpfs            4024948    188768   3836180   5% /dev/shm
tmpfs               5120         4      5116   1% /run/lock
tmpfs            4024948         0   4024948   0% /sys/fs/cgroup
cgroup2                0         0         0    - /sys/fs/cgroup/unified
cgroup                 0         0         0    - /sys/fs/cgroup/systemd
pstore                 0         0         0    - /sys/fs/pstore
none                   0         0         0    - /sys/fs/bpf
cgroup                 0         0         0    - /sys/fs/cgroup/blkio
cgroup                 0         0         0    - /sys/fs/cgroup/rdma
cgroup                 0         0         0    - /sys/fs/cgroup/hugetlb
nfsd                   0         0         0    - /proc/fs/nfsd
/dev/loop0        212096    212096         0 100% /snap/code/64
/dev/loop1        212096    212096         0 100% /snap/code/65
/dev/loop3        101376    101376         0 100% /snap/core/11081
/dev/loop2        101632    101632         0 100% /snap/core/10958
/dev/loop5         56832     56832         0 100% /snap/core18/1997
/dev/loop4         56832     56832         0 100% /snap/core18/1988
/dev/loop6        223232    223232         0 100% /snap/gnome-3-34-1804/60
/dev/loop7        224256    224256         0 100% /snap/gnome-3-34-1804/66
/dev/loop8         66688     66688         0 100% /snap/gtk-common-themes/1515
/dev/loop10        52352     52352         0 100% /snap/snap-store/498
/dev/loop9         66432     66432         0 100% /snap/gtk-common-themes/1514
/dev/loop11        52352     52352         0 100% /snap/snap-store/518
tmpfs             804988        16    804972   1% /run/user/1000
gvfsd-fuse             0         0         0    - /run/user/1000/gvfs
/dev/sda3       83105328  75133584   3707144  96% /media/thehero/e3ef9af4-7136-4650-8365-c6c02d0d14f4
/dev/sda1      218593248  53836172 164757076  25% /media/thehero/01D5FAEEFC8E1CB0

Display Disk Space in Human Readable Format

Use -h option to display sizes in human readable format, showing the size in 1 KB blocks is not very user-friendly.

 df -h
Filesystem      Size  Used Avail Use% Mounted on
udev            3.9G     0  3.9G   0% /dev
tmpfs           787M  1.6M  785M   1% /run
/dev/sda2       173G  111G   54G  68% /
tmpfs           3.9G  186M  3.7G   5% /dev/shm
tmpfs           5.0M  4.0K  5.0M   1% /run/lock
tmpfs           3.9G     0  3.9G   0% /sys/fs/cgroup
/dev/loop0      208M  208M     0 100% /snap/code/64
/dev/loop1      208M  208M     0 100% /snap/code/65
/dev/loop3       99M   99M     0 100% /snap/core/11081
/dev/loop2      100M  100M     0 100% /snap/core/10958
/dev/loop5       56M   56M     0 100% /snap/core18/1997
/dev/loop4       56M   56M     0 100% /snap/core18/1988
/dev/loop6      218M  218M     0 100% /snap/gnome-3-34-1804/60
/dev/loop7      219M  219M     0 100% /snap/gnome-3-34-1804/66
/dev/loop8       66M   66M     0 100% /snap/gtk-common-themes/1515
/dev/loop10      52M   52M     0 100% /snap/snap-store/498
/dev/loop9       65M   65M     0 100% /snap/gtk-common-themes/1514
/dev/loop11      52M   52M     0 100% /snap/snap-store/518
tmpfs           787M   16K  787M   1% /run/user/1000
/dev/sda3        80G   72G  3.6G  96% /media/thehero/e3ef9af4-7136-4650-8365-c6c02d0d14f4
/dev/sda1       209G   52G  158G  25% /media/thehero/01D5FAEEFC8E1CB0

Display Used or Available Inodes

Use -i option to list inode information instead of block usage.

df -i
Filesystem        Inodes  IUsed     IFree IUse% Mounted on
udev              998624    541    998083    1% /dev
tmpfs            1006237    991   1005246    1% /run
/dev/sda2       11558912 427755  11131157    4% /
tmpfs            1006237    106   1006131    1% /dev/shm
tmpfs            1006237      8   1006229    1% /run/lock
tmpfs            1006237     18   1006219    1% /sys/fs/cgroup
/dev/loop0          4485   4485         0  100% /snap/code/64
/dev/loop1          4485   4485         0  100% /snap/code/65
/dev/loop3         12842  12842         0  100% /snap/core/11081
/dev/loop2         12841  12841         0  100% /snap/core/10958
/dev/loop5         10790  10790         0  100% /snap/core18/1997
/dev/loop4         10817  10817         0  100% /snap/core18/1988
/dev/loop6         18513  18513         0  100% /snap/gnome-3-34-1804/60
/dev/loop7         18508  18508         0  100% /snap/gnome-3-34-1804/66
/dev/loop8         64986  64986         0  100% /snap/gtk-common-themes/1515
/dev/loop10        15847  15847         0  100% /snap/snap-store/498
/dev/loop9         63978  63978         0  100% /snap/gtk-common-themes/1514
/dev/loop11        15847  15847         0  100% /snap/snap-store/518
/dev/sda3        5316608   1536   5315072    1% /media/thehero/e3ef9af4-7136-4650-8365-c6c02d0d14f4
/dev/sda1      164789844  13761 164776083    1% /media/thehero/01D5FAEEFC8E1CB0
tmpfs            1006237     45   1006192    1% /run/user/1000

Print The Type of Filesystem

Use -T to display the type of each filesytem.

df -T
Filesystem     Type     1K-blocks      Used Available Use% Mounted on
udev           devtmpfs   3994496         0   3994496   0% /dev
tmpfs          tmpfs       804992      1576    803416   1% /run
/dev/sda2      ext4     180876872 115920592  55698504  68% /
tmpfs          tmpfs      4024948    140772   3884176   4% /dev/shm
tmpfs          tmpfs         5120         4      5116   1% /run/lock
tmpfs          tmpfs      4024948         0   4024948   0% /sys/fs/cgroup
/dev/loop0     squashfs    212096    212096         0 100% /snap/code/64
/dev/loop1     squashfs    212096    212096         0 100% /snap/code/65
/dev/loop3     squashfs    101376    101376         0 100% /snap/core/11081
/dev/loop2     squashfs    101632    101632         0 100% /snap/core/10958
/dev/loop5     squashfs     56832     56832         0 100% /snap/core18/1997
/dev/loop4     squashfs     56832     56832         0 100% /snap/core18/1988
/dev/loop6     squashfs    223232    223232         0 100% /snap/gnome-3-34-1804/60
/dev/loop7     squashfs    224256    224256         0 100% /snap/gnome-3-34-1804/66
/dev/loop8     squashfs     66688     66688         0 100% /snap/gtk-common-themes/1515
/dev/loop10    squashfs     52352     52352         0 100% /snap/snap-store/498
/dev/loop9     squashfs     66432     66432         0 100% /snap/gtk-common-themes/1514
/dev/loop11    squashfs     52352     52352         0 100% /snap/snap-store/518
/dev/sda3      ext4      83105328  75133584   3707144  96% /media/thehero/e3ef9af4-7136-4650-8365-c6c02d0d14f4
/dev/sda1      fuseblk  218593248  53836172 164757076  25% /media/thehero/01D5FAEEFC8E1CB0
tmpfs          tmpfs       804988        12    804976   1% /run/user/1000

Display Filesystem of Given Type

Using -t option can show only filesystems of a given type with -t TYPE.

df -ht ext4
Filesystem      Size  Used Avail Use% Mounted on
/dev/sda2       173G  111G   54G  68% /
/dev/sda3        80G   72G  3.6G  96% /media/thehero/e3ef9af4-7136-4650-8365-c6c02d0d14f4

Exclude Filesystem of Given Type

Using -x option will exclude filesystems of a given type with -x TYPE.

df -hx squashfs
Filesystem      Size  Used Avail Use% Mounted on
udev            3.9G     0  3.9G   0% /dev
tmpfs           787M  1.6M  785M   1% /run
/dev/sda2       173G  111G   54G  68% /
tmpfs           3.9G  132M  3.8G   4% /dev/shm
tmpfs           5.0M  4.0K  5.0M   1% /run/lock
tmpfs           3.9G     0  3.9G   0% /sys/fs/cgroup
/dev/sda3        80G   72G  3.6G  96% /media/thehero/e3ef9af4-7136-4650-8365-c6c02d0d14f4
/dev/sda1       209G   52G  158G  25% /media/thehero/01D5FAEEFC8E1CB0
tmpfs           787M   16K  787M   1% /run/user/1000

Displaying The Output

Using --output option will output format defined by FIELD_LIST, or print all fields if FIELD_LIST is omitted.

print all fields if FIELD_LIST is omitted.

df -h --output
Filesystem     Type     Inodes IUsed IFree IUse%  Size  Used Avail Use% File Mounted on
udev           devtmpfs   976K   541  975K    1%  3.9G     0  3.9G   0% -    /dev
tmpfs          tmpfs      983K   990  982K    1%  787M  1.6M  785M   1% -    /run
/dev/sda2      ext4        12M  418K   11M    4%  173G  111G   54G  68% -    /
tmpfs          tmpfs      983K    97  983K    1%  3.9G  132M  3.8G   4% -    /dev/shm
tmpfs          tmpfs      983K     8  983K    1%  5.0M  4.0K  5.0M   1% -    /run/lock
tmpfs          tmpfs      983K    18  983K    1%  3.9G     0  3.9G   0% -    /sys/fs/cgroup
/dev/loop0     squashfs   4.4K  4.4K     0  100%  208M  208M     0 100% -    /snap/code/64
/dev/loop1     squashfs   4.4K  4.4K     0  100%  208M  208M     0 100% -    /snap/code/65
/dev/loop3     squashfs    13K   13K     0  100%   99M   99M     0 100% -    /snap/core/11081
/dev/loop2     squashfs    13K   13K     0  100%  100M  100M     0 100% -    /snap/core/10958
/dev/loop5     squashfs    11K   11K     0  100%   56M   56M     0 100% -    /snap/core18/1997
/dev/loop4     squashfs    11K   11K     0  100%   56M   56M     0 100% -    /snap/core18/1988
/dev/loop6     squashfs    19K   19K     0  100%  218M  218M     0 100% -    /snap/gnome-3-34-1804/60
/dev/loop7     squashfs    19K   19K     0  100%  219M  219M     0 100% -    /snap/gnome-3-34-1804/66
/dev/loop8     squashfs    64K   64K     0  100%   66M   66M     0 100% -    /snap/gtk-common-themes/1515
/dev/loop10    squashfs    16K   16K     0  100%   52M   52M     0 100% -    /snap/snap-store/498
/dev/loop9     squashfs    63K   63K     0  100%   65M   65M     0 100% -    /snap/gtk-common-themes/1514
/dev/loop11    squashfs    16K   16K     0  100%   52M   52M     0 100% -    /snap/snap-store/518
/dev/sda3      ext4       5.1M  1.5K  5.1M    1%   80G   72G  3.6G  96% -    /media/thehero/e3ef9af4-7136-4650-8365-c6c02d0d14f4
/dev/sda1      fuseblk    158M   14K  158M    1%  209G   52G  158G  25% -    /media/thehero/01D5FAEEFC8E1CB0
tmpfs          tmpfs      983K    47  983K    1%  787M   16K  787M   1% -    /run/user/1000

You can also customize the output of df, selecting what should be displayed and in which order, using the --output= parameter followed by a comma separated list of fields you wish to display. Some of the available fields are:

  • source: The device corresponding to the filesystem.
  • fstype: The filesystem type.
  • size: The total size of the filesystem.
  • used: How much space is being used.
  • avail: How much space is available.
  • pcent: The usage percentage.
  • target: Where the filesystem is mounted (mount point).

Let’s output the target, source, type and usage.

df -h --output=target,source,fstype,pcent
Mounted on                                        Filesystem     Type     Use%
/dev                                              udev           devtmpfs   0%
/run                                              tmpfs          tmpfs      1%
/                                                 /dev/sda2      ext4      68%
/dev/shm                                          tmpfs          tmpfs      4%
/run/lock                                         tmpfs          tmpfs      1%
/sys/fs/cgroup                                    tmpfs          tmpfs      0%
/snap/code/64                                     /dev/loop0     squashfs 100%
/snap/code/65                                     /dev/loop1     squashfs 100%
/snap/core/11081                                  /dev/loop3     squashfs 100%
/snap/core/10958                                  /dev/loop2     squashfs 100%
/snap/core18/1997                                 /dev/loop5     squashfs 100%
/snap/core18/1988                                 /dev/loop4     squashfs 100%
/snap/gnome-3-34-1804/60                          /dev/loop6     squashfs 100%
/snap/gnome-3-34-1804/66                          /dev/loop7     squashfs 100%
/snap/gtk-common-themes/1515                      /dev/loop8     squashfs 100%
/snap/snap-store/498                              /dev/loop10    squashfs 100%
/snap/gtk-common-themes/1514                      /dev/loop9     squashfs 100%
/snap/snap-store/518                              /dev/loop11    squashfs 100%
/media/thehero/e3ef9af4-7136-4650-8365-c6c02d0d14f4 /dev/sda3      ext4      96%
/media/thehero/01D5FAEEFC8E1CB0                     /dev/sda1      fuseblk   25%
/run/user/1000                                    tmpfs          tmpfs      1%

df can also be used to check inode information, by passing the following fields to --output=:

  • itotal: The total number of inodes in the filesystem.
  • iused: The number of used inodes in the filesystem.
  • iavail: The number of available inodes in the filesystem.
  • ipcent: The percentage of used inodes in the filesystem.

example;

df --output=source,fstype,itotal,iused,ipcent
Filesystem     Type        Inodes  IUsed IUse%
udev           devtmpfs    998624    541    1%
tmpfs          tmpfs      1006237    990    1%
/dev/sda2      ext4      11558912 427939    4%
tmpfs          tmpfs      1006237    101    1%
tmpfs          tmpfs      1006237      8    1%
tmpfs          tmpfs      1006237     18    1%
/dev/loop0     squashfs      4485   4485  100%
/dev/loop1     squashfs      4485   4485  100%
/dev/loop3     squashfs     12842  12842  100%
/dev/loop2     squashfs     12841  12841  100%
/dev/loop5     squashfs     10790  10790  100%
/dev/loop4     squashfs     10817  10817  100%
/dev/loop6     squashfs     18513  18513  100%
/dev/loop7     squashfs     18508  18508  100%
/dev/loop8     squashfs     64986  64986  100%
/dev/loop10    squashfs     15847  15847  100%
/dev/loop9     squashfs     63978  63978  100%
/dev/loop11    squashfs     15847  15847  100%
/dev/sda3      ext4       5316608   1536    1%
/dev/sda1      fuseblk  164789844  13761    1%
tmpfs          tmpfs      1006237     47    1%

Display Details of df Command

Using --help option will display options used with df command.

df --help
Usage: df [OPTION]... [FILE]...
Show information about the file system on which each FILE resides,
or all file systems by default.

Mandatory arguments to long options are mandatory for short options too.
  -a, --all             include pseudo, duplicate, inaccessible file systems
  -B, --block-size=SIZE  scale sizes by SIZE before printing them; e.g.,
                           '-BM' prints sizes in units of 1,048,576 bytes;
                           see SIZE format below
  -h, --human-readable  print sizes in powers of 1024 (e.g., 1023M)
  -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 FIELD_LIST,
                               or print all fields if FIELD_LIST 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

Display values are in units of the first available SIZE from --block-size,
and the DF_BLOCK_SIZE, BLOCK_SIZE and BLOCKSIZE environment variables.
Otherwise, units default to 1024 bytes (or 512 if POSIXLY_CORRECT is set).

The SIZE argument is an integer and optional unit (example: 10K is 10*1024).
Units are K,M,G,T,P,E,Z,Y (powers of 1024) or KB,MB,... (powers of 1000).

FIELD_LIST is a comma-separated list of columns to be included.  Valid
field names are: 'source', 'fstype', 'itotal', 'iused', 'iavail', 'ipcent',
'size', 'used', 'avail', 'pcent', 'file' and 'target' (see info page).

GNU coreutils online help: <https://www.gnu.org/software/coreutils/>
Full documentation at: <https://www.gnu.org/software/coreutils/df>
or available locally via: info '(coreutils) df invocation'

Conclusion

This marks the end of our tutorial on example usage of df command on Linux, stay tuned for more similar tutorials.

Check the man page for more usage and information about df command.

man df

Similar Articles:

Encrypt and Decrypt Files with Vim Editor

Compress and Uncompress Files with zip Command in Linux

How To List Running Services on Linux

Leave a Comment