11 df Command Examples in Linux

The df command is a powerful tool that provides insights into disk usage on Linux and Unix-based systems. Whether you are an experienced sysadmin or a Linux enthusiast, understanding how to utilize the df command effectively is essential for managing disk space efficiently.

In this blog post, we will explore 11 practical examples that demonstrate the versatility and usefulness of the df command. By the end, you will have a solid understanding of how to leverage df to analyze disk usage and make informed decisions about storage management.

Syntax of df command

# df {options} {mount_point_of_filesystem}

Options of df command :

df-command-options

Sample Output of df

[root@linux-world ~]# df
Filesystem            1K-blocks   Used Available Use% Mounted on
/dev/mapper/vg00-root  17003304 804668  15311852   5% /
devtmpfs                 771876      0    771876   0% /dev
tmpfs                    777928      0    777928   0% /dev/shm
tmpfs                    777928   8532    769396   2% /run
tmpfs                    777928      0    777928   0% /sys/fs/cgroup
/dev/mapper/vg00-home  14987616  41000  14162232   1% /home
/dev/sda1                487652  62593    395363  14% /boot
/dev/mapper/vg00-var    9948012  48692   9370936   1% /var
/dev/mapper/vg00-sap   14987656  37636  14165636   1% /sap
[root@linux-world ~]#

1. Display Disk Usage of all the file systems

when we use ‘-a’ option in df command , it will display disk usage of all the file systems.

[root@linux-world ~]# df -a
Filesystem            1K-blocks   Used Available Use% Mounted on
rootfs                 17003304 804668  15311852   5% /
proc                          0      0         0    - /proc
sysfs                         0      0         0    - /sys
devtmpfs                 771876      0    771876   0% /dev
securityfs                    0      0         0    - /sys/kernel/security
tmpfs                    777928      0    777928   0% /dev/shm
devpts                        0      0         0    - /dev/pts
tmpfs                    777928   8532    769396   2% /run
tmpfs                    777928      0    777928   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/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/devices
cgroup                        0      0         0    - /sys/fs/cgroup/freezer
cgroup                        0      0         0    - /sys/fs/cgroup/net_cls
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/vg00-root  17003304 804668  15311852   5% /
selinuxfs                     0      0         0    - /sys/fs/selinux
systemd-1                     0      0         0    - /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/mapper/vg00-home  14987616  41000  14162232   1% /home
/dev/sda1                487652  62593    395363  14% /boot
/dev/mapper/vg00-var    9948012  48692   9370936   1% /var
/dev/mapper/vg00-sap   14987656  37636  14165636   1% /sap
[root@linux-world ~]#

2. df Command Output in Human Readable format.

By default df command shows the file system usage in 1K blocks for all the current mounted file system, however if you want to display the output in human readable format ( e.g 5K , 500M & 5G ) then use -h option.

[root@linux-world ~]# df -h
Filesystem             Size  Used Avail Use% Mounted on
/dev/mapper/vg00-root   17G  786M   15G   5% /
devtmpfs               754M     0  754M   0% /dev
tmpfs                  760M     0  760M   0% /dev/shm
tmpfs                  760M  8.4M  752M   2% /run
tmpfs                  760M     0  760M   0% /sys/fs/cgroup
/dev/mapper/vg00-home   15G   41M   14G   1% /home
/dev/sda1              477M   62M  387M  14% /boot
/dev/mapper/vg00-var   9.5G   48M  9.0G   1% /var
/dev/mapper/vg00-sap    15G   37M   14G   1% /sap
[root@linux-world ~]#

Note: If you want to sort the df output based on disk usage, you can pipe the command’s output to the sort utility. For instance,

# df -h | sort -k 5 -h

Above command will display filesystems in ascending order of usage (highest usage at the bottom).

In order to filter df output based on specific criteria, you can pipe it to the grep command. For instance,

# df -h | grep "/dev/sda"  //This will display only the filesystem associated with /dev/sda.

3. Displaying Specific Filesystem Disk Usage

To obtain information about specific filesystems, provide their mount points as arguments to the df command. For example, df -h /home will display disk usage details for the /home filesystem only.

Suppose we want to print disk space usage of /sap file system,run

[root@linux-world ~]# df -h /sap/
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/vg00-sap   15G   37M   14G   1% /sap
[root@linux-world ~]#

4. Print File System Type

To include the filesystem type in the df output, use the -T option. This provides valuable information about the filesystem format, such as ext3/4, xfs, or tmpfs, alongside disk usage statistics.

[root@linux-world ~]# df -T
Filesystem            Type     1K-blocks   Used Available Use% Mounted on
/dev/mapper/vg00-root ext4      17003304 804668  15311852   5% /
devtmpfs              devtmpfs    771876      0    771876   0% /dev
tmpfs                 tmpfs       777928      0    777928   0% /dev/shm
tmpfs                 tmpfs       777928   8532    769396   2% /run
tmpfs                 tmpfs       777928      0    777928   0% /sys/fs/cgroup
/dev/mapper/vg00-home ext4      14987616  41000  14162232   1% /home
/dev/sda1             ext3        487652  62593    395363  14% /boot
/dev/mapper/vg00-var  ext3       9948012  48696   9370932   1% /var
/dev/mapper/vg00-sap  ext3      14987656  37636  14165636   1% /sap
[root@linux-world ~]#

By employing the -T option along with the watch command (e.g., watch -n 1 “df -hT”), you can create a live updating display of disk space usage. This is useful for tracking changes or observing disk usage patterns over time.

5. Displaying Disk Space in 1K Blocks

To view disk space usage in 1K blocks rather than the default human-readable format, use the -k option (e.g., df -k). This can be beneficial when working with scripts or when precise calculations are required.

[root@linux-world ~]# df -k
Filesystem            1K-blocks   Used Available Use% Mounted on
/dev/mapper/vg00-root  17003304 804668  15311852   5% /
devtmpfs                 771876      0    771876   0% /dev
tmpfs                    777928      0    777928   0% /dev/shm
tmpfs                    777928   8532    769396   2% /run
tmpfs                    777928      0    777928   0% /sys/fs/cgroup
/dev/mapper/vg00-home  14987616  41000  14162232   1% /home
/dev/sda1                487652  62593    395363  14% /boot
/dev/mapper/vg00-var    9948012  48696   9370932   1% /var
/dev/mapper/vg00-sap   14987656  37636  14165636   1% /sap
[root@linux-world ~]#

6. Display Inodes Usage

In addition to disk space, df can also provide information about inode usage – the number of files and directories within a filesystem. Use the -i option (e.g., df -i) to see inode-related statistics.

inodes info of all the file system :

[root@linux-world ~]# df -i
Filesystem             Inodes IUsed   IFree IUse% Mounted on
/dev/mapper/vg00-root 1089536 22031 1067505    3% /
devtmpfs               192969   357  192612    1% /dev
tmpfs                  194482     1  194481    1% /dev/shm
tmpfs                  194482   420  194062    1% /run
tmpfs                  194482    13  194469    1% /sys/fs/cgroup
/dev/mapper/vg00-home  960992    15  960977    1% /home
/dev/sda1              128016   337  127679    1% /boot
/dev/mapper/vg00-var   640848  1235  639613    1% /var
/dev/mapper/vg00-sap   960992    11  960981    1% /sap
[root@linux-world ~]#

inodes info of particular file system :

[root@linux-world ~]# df -i /sap/
Filesystem           Inodes IUsed  IFree IUse% Mounted on
/dev/mapper/vg00-sap 960992    11 960981    1% /sap
[root@linux-world ~]#

7. Display Grand Total Space Usage

‘–total’ option in df command is used to display the grand total of disk usage of all the file system.

[root@linux-world ~]# df -h --total
Filesystem             Size  Used Avail Use% Mounted on
/dev/mapper/vg00-root   17G  786M   15G   5% /
devtmpfs               754M     0  754M   0% /dev
tmpfs                  760M     0  760M   0% /dev/shm
tmpfs                  760M  8.4M  752M   2% /run
tmpfs                  760M     0  760M   0% /sys/fs/cgroup
/dev/mapper/vg00-home   15G   41M   14G   1% /home
/dev/sda1              477M   62M  387M  14% /boot
/dev/mapper/vg00-var   9.5G   48M  9.0G   1% /var
/dev/mapper/vg00-sap    15G   37M   14G   1% /sap
total                   58G  980M   54G   2% -
[root@linux-world ~]#

8) Limiting the output to local file system

Suppose network file system also mounted on our linux system and but we want to display local file system information only, this can be achieved by using ‘-l’ option in df command.

nfs4-fs-mount

[root@linux-world ~]# df -Thl
Filesystem            Type      Size  Used Avail Use% Mounted on
/dev/mapper/vg00-root ext4       17G  791M   15G   6% /
devtmpfs              devtmpfs  754M     0  754M   0% /dev
tmpfs                 tmpfs     760M     0  760M   0% /dev/shm
tmpfs                 tmpfs     760M  8.4M  752M   2% /run
tmpfs                 tmpfs     760M     0  760M   0% /sys/fs/cgroup
/dev/mapper/vg00-home ext4       15G   41M   14G   1% /home
/dev/sda1             ext3      477M   62M  387M  14% /boot
/dev/mapper/vg00-var  ext3      9.5G  105M  8.9G   2% /var
/dev/mapper/vg00-sap  ext3       15G   37M   14G   1% /sap
[root@linux-world ~]#

9) Disk Information of Particular File System Type

‘-t’ option in df command is used to print information of particular file system type, after ‘-t’ specify the file system type, example is shown below :

ext4 :

[root@linux-world ~]# df -t ext4
Filesystem            1K-blocks   Used Available Use% Mounted on
/dev/mapper/vg00-root  17003304 809492  15307028   6% /
/dev/mapper/vg00-home  14987616  41000  14162232   1% /home
[root@linux-world ~]#

nfs4 :

[root@linux-world ~]# df -t nfs4
Filesystem            1K-blocks      Used Available Use% Mounted on
192.168.1.5:/opensuse 301545472 266833920  19371008  94% /data
[root@linux-world ~]#

10. Excluding Pseudo Filesystems

Pseudo filesystems such as /proc, /sys, and /dev do not represent physical storage and may skew disk usage analysis. Use the df -x command followed by the filesystem type (e.g, df -x tmpfs) to exclude these filesystems from the output.

Let suppose we want to print all the file systems excluding ext3 file system.

[root@linux-world ~]# df -x ext3
Filesystem            1K-blocks      Used Available Use% Mounted on
/dev/mapper/vg00-root  17003304    809492  15307028   6% /
devtmpfs                 771876         0    771876   0% /dev
tmpfs                    777928         0    777928   0% /dev/shm
tmpfs                    777928      8540    769388   2% /run
tmpfs                    777928         0    777928   0% /sys/fs/cgroup
/dev/mapper/vg00-home  14987616     41000  14162232   1% /home
192.168.1.5:/opensuse 301545472 266834944  19369984  94% /data
[root@linux-world ~]#

11. Print only Specific Fields in the Output

‘–output={field_name1,field_name2….}’ option is used to display the certain fields in df command output.

Valid field names are: ‘source’, ‘fstype’, ‘itotal’, ‘iused’, ‘iavail’, ‘ipcent’, ‘size’, ‘used’, ‘avail’, ‘pcent’ and ‘target’

[root@linux-world ~]# df --output=fstype,size,iused
Type     1K-blocks  IUsed
ext4      17003304  22275
devtmpfs    771876    357
tmpfs       777928      1
tmpfs       777928    423
tmpfs       777928     13
ext4      14987616     15
ext3        487652    337
ext3       9948012   1373
ext3      14987656     11
nfs4     301545472 451099
[root@linux-world ~]#

Conclusion:

The df command is a versatile tool for analyzing disk usage on Linux and Unix systems. By mastering its various options and combining it with other commands like sort, grep, and du, you can obtain valuable insights into your filesystems’ storage utilization. This blog post has provided you with 11 practical examples showcasing the power of the df command. Armed with this knowledge, you can confidently manage disk space, identify potential storage issues, and optimize your system’s storage resources. Remember to explore the man page for df to discover additional options and customize your disk usage analysis even further.

Also Read : 8 Stat Command Examples in Linux

3 thoughts on “11 df Command Examples in Linux”

Leave a Reply to Pradeep Kumar Cancel reply