df command in Linux with Examples


Advertisements

Name

df - report file system disk space usage.

Synopsis

df [OPTION]... [FILE]...

Options

-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
--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 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
-x, --exclude-type=TYPE
   limit listing to file systems not of type TYPE
--help
   display this help and exit
--version
   output version information and exit

Description

df is a strong built-in utility of linux which is used to display the amount of disk space available on the file system containing each file name argument. It can be used to show the free space on a Unix or Linux computer and to understand the filesystems that have been mounted. It supports showing usage in Bytes, Megabytes and Gigabytes. It also support including and excluding certain filesystem types from the output.

The disk space can be viewed by using df command. This will print a table of information to standard output. This can be useful to discover the amount of free space available on a system or filesystems.

Each line includes the following columns:

  • “Filesystem” - The name of the filesystem.
  • “1K-blocks” - The size of the filesystem in 1K blocks.
  • “Used” - The used space in 1K blocks.
  • “Available” - The available space in 1K blocks.
  • “Use%” - The percentage of used space.
  • “Mounted on” the directory on which the filesystem is mounted.

Examples

1. If we use df command without any option then, it would display the space available on all currently mounted file systems. By default, the df command shows the disk space in 1-kilobyte blocks and the size of used and available disk space in kilobytes.

$ df
Filesystem     1K-blocks      Used Available Use% Mounted on
udev             3985296         0   3985296   0% /dev
tmpfs             801844      2128    799716   1% /run
/dev/sda2       47799020  30241148  15100068  67% /
tmpfs            4009204     77288   3931916   2% /dev/shm
tmpfs               5120         4      5116   1% /run/lock
tmpfs            4009204         0   4009204   0% /sys/fs/cgroup
/dev/loop0           384       384         0 100% /snap/gnome-characters/539
/dev/loop1         26368     26368         0 100% /snap/heroku/3960
/dev/loop5          9344      9344         0 100% /snap/canonical-livepatch/95
/dev/loop4          9344      9344         0 100% /snap/canonical-livepatch/94
/dev/loop6          2304      2304         0 100% /snap/gnome-system-monitor/145
/dev/loop12       261760    261760         0 100% /snap/gnome-3-34-1804/33
/dev/loop13          384       384         0 100% /snap/gnome-characters/550
/dev/loop22       261760    261760         0 100% /snap/gnome-3-34-1804/36
/dev/loop19        99328     99328         0 100% /snap/core/9665
/dev/loop20       165376    165376         0 100% /snap/gnome-3-28-1804/128

2. To display information about disk drives in human-readable format (kilobytes, megabytes, gigabytes and so on), use -h option along with the df command.

$  df -h
Filesystem      Size  Used Avail Use% Mounted on
udev            3.9G     0  3.9G   0% /dev
tmpfs           784M  2.1M  781M   1% /run
/dev/sda2        46G   29G   15G  67% /
tmpfs           3.9G   80M  3.8G   3% /dev/shm
tmpfs           5.0M  4.0K  5.0M   1% /run/lock
tmpfs           3.9G     0  3.9G   0% /sys/fs/cgroup
...

3. If you want to display all the file system, use -a option.

$  df -a
Filesystem     1K-blocks      Used Available Use% Mounted on
sysfs                  0         0         0    - /sys
proc                   0         0         0    - /proc
udev             3985296         0   3985296   0% /dev
devpts                 0         0         0    - /dev/pts
tmpfs             801844      2140    799704   1% /run
/dev/sda2       47799020  30241172  15100044  67% /
securityfs             0         0         0    - /sys/kernel/security
tmpfs            4009204    141040   3868164   4% /dev/shm
tmpfs               5120         4      5116   1% /run/lock
tmpfs            4009204         0   4009204   0% /sys/fs/cgroup
cgroup                 0         0         0    - /sys/fs/cgroup/unified
cgroup                 0         0         0    - /sys/fs/cgroup/systemd
pstore                 0         0         0    - /sys/fs/pstore
cgroup                 0         0         0    - /sys/fs/cgroup/net_cls,net_prio
cgroup                 0         0         0    - /sys/fs/cgroup/hugetlb
cgroup                 0         0         0    - /sys/fs/cgroup/blkio
...

4. To display information of only device like, /home file system in human readable format use the following command.

$ df -h /home
Filesystem      Size  Used Avail Use% Mounted on
/dev/sda5       142G  106G   29G  79% /home

5. To print the information of filesystem type of a given device, use -T option along with -h option.

$ df -hT /dev/sda5
Filesystem     Type  Size  Used Avail Use% Mounted on
/dev/sda5      ext4  142G  106G   29G  79% /home

6. To display information of file system in kilo-bytes use the -k option.

$ df -k
Filesystem     1K-blocks      Used Available Use% Mounted on
udev             3985296         0   3985296   0% /dev
tmpfs             801844      2132    799712   1% /run
/dev/sda2       47799020  30241168  15100048  67% /
tmpfs            4009204    154988   3854216   4% /dev/shm
tmpfs               5120         4      5116   1% /run/lock
tmpfs            4009204         0   4009204   0% /sys/fs/cgroup
/dev/loop0           384       384         0 100% /snap/gnome-characters/539
/dev/loop1         26368     26368         0 100% /snap/heroku/3960
/dev/loop5          9344      9344         0 100% /snap/canonical-livepatch/95
/dev/loop4          9344      9344         0 100% /snap/canonical-livepatch/94
/dev/loop6          2304      2304         0 100% /snap/gnome-system-monitor/145
/dev/loop7          1024      1024         0 100% /snap/gnome-logs/93
/dev/loop8          1024      1024         0 100% /snap/gnome-logs/100
/dev/loop11        56192     56192         0 100% /snap/gtk-common-themes/1502
/dev/loop9        170496    170496         0 100% /snap/postman/119
/dev/loop10        56704     56704         0 100% /snap/core18/1885 

7. Similarly, we can display information of file system in Megabytes by using the -m option.

$ df -m
Filesystem     1M-blocks   Used Available Use% Mounted on
udev                3878      0      3878   0% /dev
tmpfs                782     78       704  10% /run
/dev/sda2          74968  15269     55869  22% /
tmpfs               3908     20      3889   1% /dev/shm
tmpfs                  5      1         5   1% /run/lock
tmpfs               3908      0      3908   0% /sys/fs/cgroup
/dev/sda3         234550   2625    219989   2% /var
/dev/sda5         144531 108058     29109  79% /home
tmpfs                782      1       782   1% /run/user/1000

8. We can use -i option to display the File System's Inodes. It displays the information of number of used inodes and their percentage for the file system.

$  df -i
Filesystem       Inodes  IUsed    IFree IUse% Mounted on
udev             996324    592   995732    1% /dev
tmpfs           1002301   1175  1001126    1% /run
/dev/sda2       3055616 237129  2818487    8% /
tmpfs           1002301    162  1002139    1% /dev/shm
tmpfs           1002301      6  1002295    1% /run/lock
tmpfs           1002301     18  1002283    1% /sys/fs/cgroup
/dev/loop0          230    230        0  100% /snap/gnome-characters/539
/dev/loop1        28237  28237        0  100% /snap/heroku/3960
/dev/loop5           34     34        0  100% /snap/canonical-livepatch/95
/dev/loop4           34     34        0  100% /snap/canonical-livepatch/94
/dev/loop6          784    784        0  100% /snap/gnome-system-monitor/145
/dev/loop7          353    353        0  100% /snap/gnome-logs/93
/dev/loop8          355    355        0  100% /snap/gnome-logs/100

9. Use -t option to display file system information of particular type of file system. For example, to display filesystem information for ext4 file system types.

$ df -t ext4
Filesystem     1K-blocks     Used Available Use% Mounted on
/dev/sda2       76766240 13230328  59613276  19% /
/dev/sda5      147999168 81044276  59413852  58% /home
/dev/sda3      240178696  9241920 218713340   5% /var

10. Use --total option in df command to display the grand total of disk usage of all the file system.

$ df --total
Filesystem     1K-blocks      Used Available Use% Mounted on
udev             3985296         0   3985296   0% /dev
tmpfs             801844      2132    799712   1% /run
/dev/sda2       47799020  30241228  15099988  67% /
tmpfs            4009204    132936   3876268   4% /dev/shm
tmpfs               5120         4      5116   1% /run/lock
tmpfs            4009204         0   4009204   0% /sys/fs/cgroup
/dev/loop0           384       384         0 100% /snap/gnome-characters/539
/dev/loop1         26368     26368         0 100% /snap/heroku/3960
/dev/loop5          9344      9344         0 100% /snap/canonical-livepatch/95
/dev/loop4          9344      9344         0 100% /snap/canonical-livepatch/94
/dev/loop6          2304      2304         0 100% /snap/gnome-system-monitor/145
/dev/loop7          1024      1024         0 100% /snap/gnome-logs/93
/dev/loop8          1024      1024         0 100% /snap/gnome-logs/100
/dev/loop11        56192     56192         0 100% /snap/gtk-common-themes/1502
/dev/loop9        170496    170496         0 100% /snap/postman/119
/dev/loop10        56704     56704         0 100% /snap/core18/1885
/dev/loop12       261760    261760         0 100% /snap/gnome-3-34-1804/33
/dev/loop13          384       384         0 100% /snap/gnome-characters/550
/dev/loop14        56320     56320         0 100% /snap/core18/1880
/dev/loop15         2304      2304         0 100% /snap/gnome-system-monitor/148
/dev/loop16       164096    164096         0 100% /snap/gnome-3-28-1804/116
/dev/loop17         2560      2560         0 100% /snap/gnome-calculator/748
/dev/loop21         2560      2560         0 100% /snap/gnome-calculator/730
/dev/loop18        63616     63616         0 100% /snap/gtk-common-themes/1506
/dev/loop22       261760    261760         0 100% /snap/gnome-3-34-1804/36
/dev/loop19        99328     99328         0 100% /snap/core/9665
/dev/loop20       165376    165376         0 100% /snap/gnome-3-28-1804/128
/dev/loop23        26368     26368         0 100% /snap/heroku/3962
/dev/sda3       19091540    160768  17937904   1% /boot
/dev/sda5       47799020   3128052  42213164   7% /usr/local
/dev/sda4      575691856 283071664 263306912  52% /home
tmpfs             801840        28    801812   1% /run/user/121
tmpfs             801840        68    801772   1% /run/user/1000
/dev/loop24       170496    170496         0 100% /snap/postman/120
/dev/loop2         98944     98944         0 100% /snap/core/9804
/dev/sdb        15737824   8388656   7349168  54% /media/rajat/p
total          722242664 326834592 360186316  48% -

11. To exclude particular type of file system information from the listing of df command, use --exclude or --exclude-type option

$ df --exclude-type=tmpfs --exclude-type=squashfs -T
Filesystem     Type     1K-blocks     Used Available Use% Mounted on
udev           devtmpfs   3970520        0   3970520   0% /dev
/dev/sda2      ext4      76766240 13230328  59613276  19% /
/dev/sda5      ext4     147999168 81044308  59413820  58% /home
/dev/sda3      ext4     240178696  9242512 218712748   5% /var
$ df --exclude=tmpfs --exclude=squashfs -T
Filesystem     Type     1K-blocks     Used Available Use% Mounted on
udev           devtmpfs   3970520        0   3970520   0% /dev
/dev/sda2      ext4      76766240 13230328  59613276  19% /
/dev/sda5      ext4     147999168 81044308  59413820  58% /home
/dev/sda3      ext4     240178696  9242512 218712748   5% /var

12. To display the disk usage information on the hard disk having ext4 filing system

$ df -t ext4 --total -h
Filesystem      Size  Used Avail Use% Mounted on
/dev/sda2        74G   13G   57G  19% /
/dev/sda5       142G   78G   57G  58% /home
/dev/sda3       230G  8.9G  209G   5% /var
total           444G   99G  323G  24% -

13. To control the output fields in df command use option --output=FIELD_LIST. FIELD_LIST is a comma separated list of columns to be included in the output of df command. Valid field names in the FIELD_LIST are listed below.

‘source’
   The source of the mount point, usually a device.
‘fstype’
   File system type.
‘itotal’
   Total number of inodes.
‘iused’
   Number of used inodes.
‘iavail’
   Number of available inodes.
‘ipcent’
   Percentage of IUSED divided by ITOTAL.
‘size’
   Total number of blocks.
‘used’
   Number of used blocks.
‘avail’
   Number of available blocks.
‘pcent’
   Percentage of USED divided by SIZE.
‘file’
   The file name if specified on the command line.
‘target’
   The mount point.
$ df --output=source,size,used,avail,fstype
Filesystem     1K-blocks     Used     Avail Type
udev             3970520        0   3970520 devtmpfs
tmpfs             800212    79696    720516 tmpfs
/dev/sda2       76766240 13230328  59613276 ext4
tmpfs            4001048    86332   3914716 tmpfs
tmpfs               5120        4      5116 tmpfs
tmpfs            4001048        0   4001048 tmpfs
/dev/sda5      147999168 81044160  59413968 ext4
/dev/sda3      240178696  9243600 218711660 ext4  
Advertisements