14 Simple df (Disk Free) Command Examples For Linux

The ‘df’ command is used to quickly print an overview of the disk space in use on different partitions and file systems.

df comes from the GNU Coreutils package and should be available by default in Unix/Linux based operating systems.

By the end of this guide you should know how to use df to view overall disk space usage in Linux. If you’re after a way of more specifically finding the files that are using disk space, we recommend using the du command instead.

How To use df – Command Examples

  • 1. Running df

    If we run the df command with no options, it will print out disk usage information for all mounted file systems.

    [root@centos7 ~]# df
    Filesystem              1K-blocks    Used Available Use% Mounted on
    /dev/mapper/centos-root  18307072 3444056  14863016  19% /
    devtmpfs                  1922332       0   1922332   0% /dev
    tmpfs                     1933472       0   1933472   0% /dev/shm
    tmpfs                     1933472    8800   1924672   1% /run
    tmpfs                     1933472       0   1933472   0% /sys/fs/cgroup
    /dev/sda1                  508588  145732    362856  29% /boot
    tmpfs                      386696       0    386696   0% /run/user/0
    

    The output is pretty simple to understand. First the file system is listed, followed by the total space, the used space, the space free, the percentage used, and where the file system is mounted to. By default the block size is based on units of 1024 bytes, however this can be changed as shown in point 11.

  • 2. Human Readable Output

    As we have seen above, the printed output shows all sizes in KB by default. We can optionally specify the -h option which will display the output in human readable format, showing sizes in MB and GB for example which is easier to understand.

    [root@centos7 ~]# df -h
    Filesystem               Size  Used Avail Use% Mounted on
    /dev/mapper/centos-root   18G  3.3G   15G  19% /
    devtmpfs                 1.9G     0  1.9G   0% /dev
    tmpfs                    1.9G     0  1.9G   0% /dev/shm
    tmpfs                    1.9G  8.6M  1.9G   1% /run
    tmpfs                    1.9G     0  1.9G   0% /sys/fs/cgroup
    /dev/sda1                497M  143M  355M  29% /boot
    tmpfs                    378M     0  378M   0% /run/user/0
    
  • 3. Print Totals

    So far with df we can print out the usage of each individual file system. With the --total option we can get an overall result.

    [root@centos7 ~]# df --total -h
    Filesystem               Size  Used Avail Use% Mounted on
    /dev/mapper/centos-root   18G  3.3G   15G  19% /
    devtmpfs                 1.9G     0  1.9G   0% /dev
    tmpfs                    1.9G     0  1.9G   0% /dev/shm
    tmpfs                    1.9G  8.6M  1.9G   1% /run
    tmpfs                    1.9G     0  1.9G   0% /sys/fs/cgroup
    /dev/sda1                497M  143M  355M  29% /boot
    tmpfs                    378M     0  378M   0% /run/user/0
    total                     26G  3.5G   23G  14% -
    

    We can see an additional line printed down the bottom which includes the total size of all file systems, the total size in use and the total size available.

  • 4. Display Inodes

    Instead of listing block usage, we can use the -i option to print inode usage.

    [root@centos7 ~]# df -hi
    Filesystem              Inodes IUsed IFree IUse% Mounted on
    /dev/mapper/centos-root    18M   41K   18M    1% /
    devtmpfs                  470K   383  469K    1% /dev
    tmpfs                     473K     1  473K    1% /dev/shm
    tmpfs                     473K   480  472K    1% /run
    tmpfs                     473K    13  473K    1% /sys/fs/cgroup
    /dev/sda1                 500K   331  500K    1% /boot
    tmpfs                     473K     1  473K    1% /run/user/0
    
  • 5. Specify File System

    By default df will show available file systems, we can specify the path to some file system to only view information related to it.

    [root@centos7 ~]# df -h /home/
    Filesystem               Size  Used Avail Use% Mounted on
    /dev/mapper/centos-root   18G  3.3G   15G  19% /
    

    In this example the /home/ directory is available through /dev/mapper/centos-root, so we are only shown information about this.

  • 6. Do Not Show External File Systems

    By default running the df command will show any externally mounted file systems, including those from external NFS or Samba servers. We can hide these external file systems from our results with the --local option.

    [root@centos7 ~]# df --local
    
  • 7. Print File System Type

    With the -T option we can see the file system type included in the output.

    [root@centos7 ~]# df -hT
    Filesystem              Type      Size  Used Avail Use% Mounted on
    /dev/mapper/centos-root xfs        18G  3.3G   15G  19% /
    devtmpfs                devtmpfs  1.9G     0  1.9G   0% /dev
    tmpfs                   tmpfs     1.9G     0  1.9G   0% /dev/shm
    tmpfs                   tmpfs     1.9G  8.6M  1.9G   1% /run
    tmpfs                   tmpfs     1.9G     0  1.9G   0% /sys/fs/cgroup
    /dev/sda1               xfs       497M  143M  355M  29% /boot
    tmpfs                   tmpfs     378M     0  378M   0% /run/user/0
    
  • 8. Show Specific File System Type

    With the -t option we can specify a particular file system and only those file systems will be printed, for example here we state that we only want to see the type of xfs and that is all that is returned.

    [root@centos7 ~]# df -ht xfs
    Filesystem               Size  Used Avail Use% Mounted on
    /dev/mapper/centos-root   18G  3.3G   15G  19% /
    /dev/sda1                497M  143M  355M  29% /boot
    
  • 9. Exclude Specific File System

    We can also do the opposite to this and exclude a specified file system type from the output, here we ignore all xfs results.

    [root@centos7 ~]# df -hx xfs
    Filesystem      Size  Used Avail Use% Mounted on
    devtmpfs        1.9G     0  1.9G   0% /dev
    tmpfs           1.9G     0  1.9G   0% /dev/shm
    tmpfs           1.9G  8.6M  1.9G   1% /run
    tmpfs           1.9G     0  1.9G   0% /sys/fs/cgroup
    tmpfs           378M     0  378M   0% /run/user/0
    
  • 10. Ensure Up To Date Results

    By default the df command runs with the --no-sync option which will not perform the sync system call prior to reporting usage information. While this may run faster, we can optionally force the sync with the --sync option which will force a sync resulting in the output being fully up to date.

    [root@centos7 ~]# df --sync
    
  • 11. Decimal Output Instead Of Binary

    While the -h option prints output in a human readable format, it also works based on powers of 1024 which is fairly standard. We can use -H instead, which works similarly except that it works based on powers of 1000.

    [root@centos7 ~]# df -H
    Filesystem               Size  Used Avail Use% Mounted on
    /dev/mapper/centos-root   19G  3.6G   16G  19% /
    devtmpfs                 2.0G     0  2.0G   0% /dev
    tmpfs                    2.0G     0  2.0G   0% /dev/shm
    tmpfs                    2.0G  9.0M  2.0G   1% /run
    tmpfs                    2.0G     0  2.0G   0% /sys/fs/cgroup
    /dev/sda1                521M  150M  372M  29% /boot
    tmpfs                    396M     0  396M   0% /run/user/0
    

    This shows information in kilobits, megabits or gigabits for example, rather than the 1024 counterparts.

  • 12. Include All File Systems

    We can print the results for all file systems with the -a option. This displays dummy file systems which are hidden by default, they are generally special file systems such as /proc with no real storage space.

    [root@centos7 ~]# df -ha
    Filesystem               Size  Used Avail Use% Mounted on
    rootfs                      -     -     -    - /
    sysfs                       0     0     0    - /sys
    proc                        0     0     0    - /proc
    devtmpfs                 1.9G     0  1.9G   0% /dev
    securityfs                  0     0     0    - /sys/kernel/security
    tmpfs                    1.9G     0  1.9G   0% /dev/shm
    devpts                      0     0     0    - /dev/pts
    tmpfs                    1.9G  8.6M  1.9G   1% /run
    tmpfs                    1.9G     0  1.9G   0% /sys/fs/cgroup
    cgroup                      0     0     0    - /sys/fs/cgroup/systemd
    pstore                      0     0     0    - /sys/fs/pstore
    cgroup                      0     0     0    - /sys/fs/cgroup/devices
    cgroup                      0     0     0    - /sys/fs/cgroup/net_cls
    cgroup                      0     0     0    - /sys/fs/cgroup/cpuset
    cgroup                      0     0     0    - /sys/fs/cgroup/cpu,cpuacct
    cgroup                      0     0     0    - /sys/fs/cgroup/memory
    cgroup                      0     0     0    - /sys/fs/cgroup/freezer
    cgroup                      0     0     0    - /sys/fs/cgroup/blkio
    cgroup                      0     0     0    - /sys/fs/cgroup/perf_event
    cgroup                      0     0     0    - /sys/fs/cgroup/hugetlb
    configfs                    0     0     0    - /sys/kernel/config
    /dev/mapper/centos-root   18G  3.3G   15G  19% /
    selinuxfs                   0     0     0    - /sys/fs/selinux
    systemd-1                   -     -     -    - /proc/sys/fs/binfmt_misc
    debugfs                     0     0     0    - /sys/kernel/debug
    hugetlbfs                   0     0     0    - /dev/hugepages
    mqueue                      0     0     0    - /dev/mqueue
    /dev/sda1                497M  143M  355M  29% /boot
    tmpfs                    378M     0  378M   0% /run/user/0
    binfmt_misc                 0     0     0    - /proc/sys/fs/binfmt_misc
    
  • 13. Display df Version

    We can view the version of df that is available with the --version option.

    [root@centos7 ~]# df --version
    df (GNU coreutils) 8.22
    Copyright (C) 2013 Free Software Foundation, Inc.
    License GPLv3+: GNU GPL version 3 or later .
    This is free software: you are free to change and redistribute it.
    There is NO WARRANTY, to the extent permitted by law.
    
    Written by Torbjörn Granlund, David MacKenzie, and Paul Eggert.
    
  • 14. Display Help

    We can show useful help information if we need further details on any of this with the --help option. Note that the full output of the command is not shown for brevity.

    [root@centos7 ~]# df --help
    Usage: df [OPTION]... [FILE]...
    

Summary

With the df command we can quickly get an overview of how much disk space each file system has available and is using. If we need to further drill down and find specific directories or files that are using the space we can use the du command.

  1. I like your post

  2. Very useful, thanks!

Leave a Comment

NOTE - You can use these HTML tags and attributes:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>