WebMasterCampus
WEB DEVELOPER Resources

Linux df Command

Learn Linux df Command with examples


Linux df Command

The df stands for “disk filesystem”. In Linux, we can use “df” command to display the disk space used in the file system.

df Command define following:

  • Number of blocks used.
  • The number of blocks available.
  • The directory where the file system is mounted.

df Command Syntax

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

df Command Options

Option Description
-a
--all
It is used to include pseudo; duplicate; remote file systems.
-B
--block-size=SIZE
It is used to scale sizes by SIZE before printing them; for example; the '-BM' option prints sizes in units of 1048576 bytes.
-h
--human-readable
It is used to display sizes in powers of 1024 (e.g 1023M).
-H
--si
It is used to show sizes in powers of 1000 (e.g 1.5G)
-i
--inodes
It is used to list inode information instead of block usage.
-l
--local
It is used to limit the listing to local file systems.
--no-sync It is used for not invoking sync before getting usage info (default).
--output[=FIELD_LIST] This option used if we want to use the output format defined by FIELD_LIST or print all fields if FIELD_LIST is omitted.
-P
--portability
It is used to use the POSIX output format.
--total It is used to exclude all entries insignificant to available space and produce a total.
-t
--type=TYPE
It is used to limit the listing to file systems of type TYPE.
-T
--print-type
It is used to display the file system type.
-x
--exclude-type=TYPE
It is used to limit the listing to file systems; not of type TYPE.
--help It is used to display the help manual having brief information about the supported options.
--version It is used to display the version information of the df command.

df Command Example

The default df command will show the disk space usage in a tabular form.

The df command is useful for discovering the available free space on a system or file system.

>> df 

Filesystem     1K-blocks      Used Available Use% Mounted on
/dev/sdb       263174212   1161336 248574720   1% /
tmpfs            3124888         0   3124888   0% /mnt/wsl
tools          146892048 110478604  36413444  76% /init
none             3122804         0   3122804   0% /dev
none             3124888         8   3124880   1% /run
none             3124888         0   3124888   0% /run/lock
none             3124888         0   3124888   0% /run/shm
none             3124888         0   3124888   0% /run/user
tmpfs            3124888         0   3124888   0% /sys/fs/cgroup
drivers        146892048 110478604  36413444  76% /usr/lib/wsl/drivers
lib            146892048 110478604  36413444  76% /usr/lib/wsl/lib
C:\            146892048 110478604  36413444  76% /mnt/c
D:\             86972412  59789760  27182652  69% /mnt/d

df -h Command

The ‘-h’ option is used to display the disk space in a human-readable form.

It will display the size in powers of 1024 and will append G for GBs, M for MBs, and B for Bytes.

>> df -h

Filesystem      Size  Used Avail Use% Mounted on
/dev/sdb        251G  1.2G  238G   1% /
tmpfs           3.0G     0  3.0G   0% /mnt/wsl
tools           141G  106G   35G  76% /init
none            3.0G     0  3.0G   0% /dev
none            3.0G  8.0K  3.0G   1% /run
none            3.0G     0  3.0G   0% /run/lock
none            3.0G     0  3.0G   0% /run/shm
none            3.0G     0  3.0G   0% /run/user
tmpfs           3.0G     0  3.0G   0% /sys/fs/cgroup
drivers         141G  106G   35G  76% /usr/lib/wsl/drivers
lib             141G  106G   35G  76% /usr/lib/wsl/lib
C:\             141G  106G   35G  76% /mnt/c
D:\              83G   58G   26G  69% /mnt/d

df -T Command

The ‘-T’ option is used to display the file system type.

It will add a new column having the file system type to output.

>> df -T  

Filesystem     Type     1K-blocks      Used Available Use% Mounted on
/dev/sdb       ext4     263174212   1161336 248574720   1% /
tmpfs          tmpfs      3124888         0   3124888   0% /mnt/wsl
tools          9p       146892048 110481704  36410344  76% /init
none           devtmpfs   3122804         0   3122804   0% /dev
none           tmpfs      3124888         8   3124880   1% /run
none           tmpfs      3124888         0   3124888   0% /run/lock
none           tmpfs      3124888         0   3124888   0% /run/shm
none           tmpfs      3124888         0   3124888   0% /run/user
tmpfs          tmpfs      3124888         0   3124888   0% /sys/fs/cgroup
drivers        9p       146892048 110481704  36410344  76% /usr/lib/wsl/drivers
lib            9p       146892048 110481704  36410344  76% /usr/lib/wsl/lib
C:\            9p       146892048 110481704  36410344  76% /mnt/c
D:\            9p        86972412  59789764  27182648  69% /mnt/d

df -t Command

The ‘-t’ option is used with the file system type to display the specific file system.

It will only display a given file system. We can specify more than one file system with it.

>> df -t ext4  

Filesystem     1K-blocks    Used Available Use% Mounted on
/dev/sdb       263174212 1161336 248574720   1% /

df -x Command

The ‘-x’ option is used with the specific file system type to exclude it from the output.

It will display all other file system types except the given types.

>> df -x squashfs

Filesystem     1K-blocks      Used Available Use% Mounted on
/dev/sdb       263174212   1161336 248574720   1% /
tmpfs            3124888         0   3124888   0% /mnt/wsl
tools          146892048 110480340  36411708  76% /init
none             3122804         0   3122804   0% /dev
none             3124888         8   3124880   1% /run
none             3124888         0   3124888   0% /run/lock
none             3124888         0   3124888   0% /run/shm
none             3124888         0   3124888   0% /run/user
tmpfs            3124888         0   3124888   0% /sys/fs/cgroup
drivers        146892048 110480340  36411708  76% /usr/lib/wsl/drivers
lib            146892048 110480340  36411708  76% /usr/lib/wsl/lib
C:\            146892048 110480340  36411708  76% /mnt/c
D:\             86972412  59789764  27182648  69% /mnt/d

Display available space and mount point for a folder

To display the available space, file system type, and mount point of a folder, pass the folder name (fruits) with the df command.

>> df fruits

Filesystem     1K-blocks    Used Available Use% Mounted on
/dev/sdb       263174212 1161336 248574720   1% /
Created with love and passion.