Open In App

df Command in Linux with examples

There might come a situation while using Linux when you want to know the amount of space consumed by a particular file system on your LINUX system or how much space is available on a particular file system. LINUX being command friendly provides a command line utility for this i.e df command that displays the amount of disk space available on the file system containing each file name argument.

df Syntax : 



df [OPTION]...[FILE]...
OPTION : to the options compatible with df command 
FILE : specific filename in case you want to know 
the disk space usage of a particular file system only. 

Using df command

Suppose you have a file named kt.txt and you want to know the used disk space on the file system that contains this file then you can use df in this case as: 



// using df for a specific file //

$df kt.txt
Filesystem     1K-blocks      Used Available Use% Mounted on 
/dev/the2        1957124      1512   1955612   1% /snap/core 

/* the df only showed the disk usage 
details of the file system that
contains file kt.txt */

Now, what if you don’t give any filename t df, in that case df displays the disk usage information for all mounted file systems as shown below: 

//using df without any filename //

$df
Filesystem     1K-blocks      Used Available Use% Mounted on
/dev/loop0      18761008  15246876   2554440  86% /
none                   4         0         4   0% /sys/fs/cgroup
udev              493812         4    493808   1% /dev
tmpfs             100672      1364     99308   2% /run
none                5120         0      5120   0% /run/lock
none              503352      1764    501588   1% /run/shm
none              102400        20    102380   1% /run/user
/dev/the2        1957124      1512   1955612   1% /snap/core 

/* in this case df displayed 
the disk usage details of all
mounted file systems */

Options for df command

Examples of using df with options

1. Using -a : If there is a need to display all file systems along with those which has zero block sizes then use -a option with df. 

//using df with -a//

$df -a
Filesystem     1K-blocks      Used Available Use% Mounted on
/dev/loop0      18761008  15246876   2554440  86% /
none                   4         0         4   0% /sys/fs/cgroup
udev              493812         4    493808   1% /dev
tmpfs             100672      1364     99308   2% /run
none                5120         0      5120   0% /run/lock
none              503352      1764    501588   1% /run/shm
none              102400        20    102380   1% /run/user
/dev/sda3      174766076 164417964  10348112  95% /host
systemd                0         0         0    - /sys/fs/cgroup

/* in this case
systemd file system 
having zero block 
size is also displayed */

2. Using -h : This is used to make df command display the output in human-readable format. 

//using -h with df//

$df -h kt.txt
Filesystem     1K-blocks      Used Available Use% Mounted on 
/dev/the2           1.9G      1.5M      1.9G   1% /snap/core 

/*this output is 
easily understandable by 
the user and all
cause of -h option */

In the above, G and M represents Gigabytes and Megabytes respectively. You can use -h with df only to produce the output in readable format for all the mounted file systems rather than just of the file system containing kt.txt file. 

3. Using -k : This displays the file system information and usage in 1 K blocks. 

//using -k with df//

$df -k kt.txt
Filesystem     1K-blocks      Used Available Use% Mounted on 
/dev/the2        1957124      1512   1955612   1% /snap/core 

/* no change cause the
output was initially
shown in the usage
of 1K bytes only */

4. Using – -total : This option is used to produce total for a size, used and available columns in the output. 

//using --total with df//

$df --total 
Filesystem     1K-blocks      Used Available Use% Mounted on
/dev/loop0      18761008  15246876   2554440  86% /
none                   4         0         4   0% /sys/fs/cgroup
udev              493812         4    493808   1% /dev
tmpfs             100672      1364     99308   2% /run
none                5120         0      5120   0% /run/lock
none              503352      1764    501588   1% /run/shm
none              102400        20    102380   1% /run/user
/dev/the2        1957124      1512   1955612   1% /snap/core 
total           21923492  15251540   5712260  92% -                       

/* the total row 
is added in the 
output */

5. Using -T : With the help of this option, you will be able to see the corresponding type of the file system as shown. 

/using -T with df//

$df -T kt.txt
Filesystem     Type     1K-blocks      Used Available Use% Mounted on 
/dev/the2      squashfs   1957124      1512   1955612   1% /snap/core 

/* you can use
-T with df only
to display type of
all the mounted
file systems */

6. Using -t : This is used when you wish the disk usage information of the file systems having a particular type only. 

//using -t with df//

$df -t squashfs
Filesystem     1K-blocks      Used Available Use% Mounted on
/dev/loop0      18761008  15246876   2554440  86% /
/dev/the2        1957124      1512   1955612   1% /snap/core 


/*so the df 
displayed only the 
info of the file
systems having type
squashfs */

7. Using -x : Now, you can also tell df to display the disk usage info of all the file systems except those having a particular type with the help of -x option. 

//using -x with df//

$df -x squashfs
Filesystem     1K-blocks      Used Available Use% Mounted on
none                   4         0         4   0% /sys/fs/cgroup
udev              493812         4    493808   1% /dev
tmpfs             100672      1364     99308   2% /run
none                5120         0      5120   0% /run/lock
none              503352      1764    501588   1% /run/shm
none              102400        20    102380   1% /run/user

/* in this case info of
/dev/the2 and /dev/loop0
file systems aren't
displayed cause they are 
of type squashfs */

8. Using -i : This option is used to display inode information in the output. 

//using -i with df//

$df -i kt.txt
Filesystem     Inodes  IUsed    IFree Iuse% Mounted on 
/dev/the2      489281     48   489233    1% /snap/core

/*showing inode info
of file system
having file kt.txt */

When -i option is used then the second, third, and fourth columns displays inode-related figures instead of disk related. 

9. Using – -sync : By default, the df command produces output with – -no-sync option which will not perform the sync system call prior to reporting usage information. Now we can use – -sync option which will force a sync resulting in the output being fully up to date. 

//using --sync option//

$df --sync
Filesystem     1K-blocks      Used Available Use% Mounted on
/dev/loop0      18761008  15246876   2554440  86% /
none                   4         0         4   0% /sys/fs/cgroup
udev              493812         4    493808   1% /dev
tmpfs             100672      1364     99308   2% /run
none                5120         0      5120   0% /run/lock
none              503352      1764    501588   1% /run/shm
none              102400        20    102380   1% /run/user
/dev/the2        1957124      1512   1955612   1% /snap/core 

/* in this case 
no change in the output
is observed cause it is 
possible that there is no
update info present to
be reflected */

10. Using -l : When we run df command then by default it shows any externally mounted file systems which include those from external NFS or Samba servers. We can hide the info of these external file systems from output with -l option syntax of which is shown below.  

$df -l

So, this is all about df command. 


Article Tags :