df command in Linux with Examples

21 Feb, 2018
The df command (short for disk free), is used to display information related to file systems about total space and available space.
Syntax :
df [OPTION]... [FILE]...

If no file name is given, it displays the space available on all currently mounted file systems.For example :
df

Output :
Filesystem     1K-blocks     Used Available Use% Mounted on
udev             3996816        0   3996816   0% /dev
tmpfs             804624    10020    794604   2% /run
/dev/sda9       68117056 18036160  46597712  28% /
tmpfs            4023116    29848   3993268   1% /dev/shm
tmpfs               5120        4      5116   1% /run/lock
tmpfs            4023116        0   4023116   0% /sys/fs/cgroup
/dev/loop0         88832    88832         0 100% /snap/simplescreenrecorder/1
/dev/loop2         85888    85888         0 100% /snap/core/3748
/dev/loop3         85888    85888         0 100% /snap/core/3604
/dev/loop1         83328    83328         0 100% /snap/core/3887
/dev/sda10      78873504 67530504   7313356  91% /home
/dev/sda1         507904    30908    476996   7% /boot/efi
tmpfs             804624       12    804612   1% /run/user/121
tmpfs             804624       64    804560   1% /run/user/1000

Now, if you specify particular file, then it will show mount information of that particular file.For example:
df /home/mandeep/test/test.cpp

Output :
Filesystem     1K-blocks     Used Available Use% Mounted on
/dev/sda10      78873504 67528220   7315640  91% /home

Options for df command :
-a, –all : includes pseudo, duplicate and inaccessible file systems.-B, –block-size=SIZE : scales sizes by SIZE before printing them.-h, –human-readable : print sizes in power of 1024-H, –si: print sizes in power of 1000-i, –inodes : list inode information instead of block usage-l, –local : limit listing to local file systems-P, –portability : use POSIX output format–sync : invoke sync before getting usage info–total : elide all entries insignificant to available space, and produce grand total-t, –type=TYPE : limit listing to file systems of type TYPE-T, –print-type : print file system type
df usage Examples with options :
If you want to display all the file system, use -a option.df -a
Output :/dev/sda10      78873504 67528540   7315320  91% /home
/dev/sda1         507904    30908    476996   7% /boot/efi
tmpfs             804624       12    804612   1% /run/user/121
tmpfs             804624       64    804560   1% /run/user/1000
gvfsd-fuse             0        0         0    - /run/user/1000/gvfs
The above is not complete output, but you can see that the information shown is extended to info provided by df command.Use -h option to display size in power of 1024df -h /home/mandeep
Output :Filesystem      Size  Used Avail Use% Mounted on
/dev/sda10       76G   65G  7.0G  91% /home
Use -H option to display sizes in power of 1000df -H /home/mandeep
Output :Filesystem      Size  Used Avail Use% Mounted on
/dev/sda10       81G   70G  7.5G  91% /home
You can observe the size section of two command with -h and -H option for difference.To get complete grand total, use –total optiondf --total
Output :Filesystem     1K-blocks     Used Available Use% Mounted on
udev             3996816        0   3996816   0% /dev
tmpfs             804624    10072    794552   2% /run
/dev/sda9       68117056 18036336  46597536  28% /
tmpfs            4023116    50140   3972976   2% /dev/shm
tmpfs               5120        4      5116   1% /run/lock
tmpfs            4023116        0   4023116   0% /sys/fs/cgroup
/dev/loop0         88832    88832         0 100% /snap/simplescreenrecorder/1
/dev/loop2         85888    85888         0 100% /snap/core/3748
/dev/loop3         85888    85888         0 100% /snap/core/3604
/dev/loop1         83328    83328         0 100% /snap/core/3887
/dev/sda10      78873504 67529320   7314540  91% /home
/dev/sda1         507904    30908    476996   7% /boot/efi
tmpfs             804624       12    804612   1% /run/user/121
tmpfs             804624       64    804560   1% /run/user/1000
total          162304440 86000792  68790820  56% -
Observe the last row of above table output, it specifies grand total.Use -T option to display file typeFor example:df -T /home/mandeep
Output :Filesystem     Type 1K-blocks     Used Available Use% Mounted on
/dev/sda10     ext4  78873504 67528128   7315732  91% /home
You can see the file type for /home/mandeep is ext4.And for more help, you can use –help option.df --help

If you want to display all the file system, use -a option.df -a
Output :/dev/sda10      78873504 67528540   7315320  91% /home
/dev/sda1         507904    30908    476996   7% /boot/efi
tmpfs             804624       12    804612   1% /run/user/121
tmpfs             804624       64    804560   1% /run/user/1000
gvfsd-fuse             0        0         0    - /run/user/1000/gvfs
The above is not complete output, but you can see that the information shown is extended to info provided by df command.
df -a

Output :
/dev/sda10      78873504 67528540   7315320  91% /home
/dev/sda1         507904    30908    476996   7% /boot/efi
tmpfs             804624       12    804612   1% /run/user/121
tmpfs             804624       64    804560   1% /run/user/1000
gvfsd-fuse             0        0         0    - /run/user/1000/gvfs

The above is not complete output, but you can see that the information shown is extended to info provided by df command.
Use -h option to display size in power of 1024df -h /home/mandeep
Output :Filesystem      Size  Used Avail Use% Mounted on
/dev/sda10       76G   65G  7.0G  91% /home

df -h /home/mandeep

Output :
Filesystem      Size  Used Avail Use% Mounted on
/dev/sda10       76G   65G  7.0G  91% /home

Use -H option to display sizes in power of 1000df -H /home/mandeep
Output :Filesystem      Size  Used Avail Use% Mounted on
/dev/sda10       81G   70G  7.5G  91% /home
You can observe the size section of two command with -h and -H option for difference.
df -H /home/mandeep

Output :
Filesystem      Size  Used Avail Use% Mounted on
/dev/sda10       81G   70G  7.5G  91% /home

You can observe the size section of two command with -h and -H option for difference.
To get complete grand total, use –total optiondf --total
Output :Filesystem     1K-blocks     Used Available Use% Mounted on
udev             3996816        0   3996816   0% /dev
tmpfs             804624    10072    794552   2% /run
/dev/sda9       68117056 18036336  46597536  28% /
tmpfs            4023116    50140   3972976   2% /dev/shm
tmpfs               5120        4      5116   1% /run/lock
tmpfs            4023116        0   4023116   0% /sys/fs/cgroup
/dev/loop0         88832    88832         0 100% /snap/simplescreenrecorder/1
/dev/loop2         85888    85888         0 100% /snap/core/3748
/dev/loop3         85888    85888         0 100% /snap/core/3604
/dev/loop1         83328    83328         0 100% /snap/core/3887
/dev/sda10      78873504 67529320   7314540  91% /home
/dev/sda1         507904    30908    476996   7% /boot/efi
tmpfs             804624       12    804612   1% /run/user/121
tmpfs             804624       64    804560   1% /run/user/1000
total          162304440 86000792  68790820  56% -
Observe the last row of above table output, it specifies grand total.
df --total

Output :
Filesystem     1K-blocks     Used Available Use% Mounted on
udev             3996816        0   3996816   0% /dev
tmpfs             804624    10072    794552   2% /run
/dev/sda9       68117056 18036336  46597536  28% /
tmpfs            4023116    50140   3972976   2% /dev/shm
tmpfs               5120        4      5116   1% /run/lock
tmpfs            4023116        0   4023116   0% /sys/fs/cgroup
/dev/loop0         88832    88832         0 100% /snap/simplescreenrecorder/1
/dev/loop2         85888    85888         0 100% /snap/core/3748
/dev/loop3         85888    85888         0 100% /snap/core/3604
/dev/loop1         83328    83328         0 100% /snap/core/3887
/dev/sda10      78873504 67529320   7314540  91% /home
/dev/sda1         507904    30908    476996   7% /boot/efi
tmpfs             804624       12    804612   1% /run/user/121
tmpfs             804624       64    804560   1% /run/user/1000
total          162304440 86000792  68790820  56% -

Observe the last row of above table output, it specifies grand total.
Use -T option to display file typeFor example:df -T /home/mandeep
Output :Filesystem     Type 1K-blocks     Used Available Use% Mounted on
/dev/sda10     ext4  78873504 67528128   7315732  91% /home
You can see the file type for /home/mandeep is ext4.
df -T /home/mandeep

Output :
Filesystem     Type 1K-blocks     Used Available Use% Mounted on
/dev/sda10     ext4  78873504 67528128   7315732  91% /home

You can see the file type for /home/mandeep is ext4.
And for more help, you can use –help option.df --help

df --help

– Mandeep Singh
References :1) df wiki2) Linux man page for df
linux-command
Linux-Unix
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
ZIP command in Linux with examples
tar command in Linux with examples
curl command in Linux with Examples
Conditional Statements | Shell Script
TCP Server-Client implementation in C
Tail command in Linux with examples
Docker - COPY Instruction
scp command in Linux with Examples
UDP Server-Client implementation in C
Cat command in Linux with examples