Site icon DesignLinux

Df Command in Linux (Check Disk Space)

Df Command in Linux (Check Disk Space)

In Linux, the df command is used to get the information about the disk space usage. This guide explains how to use the df command with different formats.

Use of df Command

Below is the basic syntax for the df command:

df [OPTIONS]... FILESYSTEM...

If you invoke the df command without any arguments, it will show the information about all mounted file systems:

df
Filesystem     1K-blocks    Used Available Use% Mounted on
udev             1007480       0   1007480   0% /dev
tmpfs             204104     620    203484   1% /run
/dev/vda1       25226960 3900508  21310068  16% /
tmpfs            1020508       0   1020508   0% /dev/shm
tmpfs               5120       0      5120   0% /run/lock
tmpfs            1020508       0   1020508   0% /sys/fs/cgroup
/dev/vda15        106858    3668    103190   4% /boot/efi
tmpfs             204100       0    204100   0% /run/user/1000

Following is the description of the each column:

To get the information for a specific filesystem, pass the name of it with the df command:

Let’s take an example from above output, if you want to show the details of /dev/vda1 filesystem, you would type:

df /dev/vda1

It will show output as following:

Filesystem     1K-blocks    Used Available Use% Mounted on
/dev/vda1       25226960 3900844  21309732  16% /

Show Disk Space Usage in Human Readable Format

The df command by default showing the disk space in 1-kilobyte blocks. Also used and available disk space showing in kilobytes.

To show the details in human-readable format means in kilobytes, megabytes, gigabytes, etc., you should pass the option -h with df command:

df -h
Filesystem      Size  Used Avail Use% Mounted on
udev            984M     0  984M   0% /dev
tmpfs           200M  620K  199M   1% /run
/dev/vda1        25G  3.8G   21G  16% /
tmpfs           997M     0  997M   0% /dev/shm
tmpfs           5.0M     0  5.0M   0% /run/lock
tmpfs           997M     0  997M   0% /sys/fs/cgroup
/dev/vda15      105M  3.6M  101M   4% /boot/efi
tmpfs           200M     0  200M   0% /run/user/1000

File System Types

You can use the -T option with df command to display file system types:

df -T

It will add the one more column named “Type”, which shows the type of the filesystem:

Filesystem     Type     1K-blocks    Used Available Use% Mounted on
udev           devtmpfs   1007480       0   1007480   0% /dev
tmpfs          tmpfs       204104     620    203484   1% /run
/dev/vda1      ext4      25226960 3900576  21310000  16% /
tmpfs          tmpfs      1020508       0   1020508   0% /dev/shm
tmpfs          tmpfs         5120       0      5120   0% /run/lock
tmpfs          tmpfs      1020508       0   1020508   0% /sys/fs/cgroup
/dev/vda15     vfat        106858    3668    103190   4% /boot/efi
tmpfs          tmpfs       204100       0    204100   0% /run/user/1000

You can filter the listing by specifying the type along with -t option:

df -t ext4
Filesystem     1K-blocks    Used Available Use% Mounted on
/dev/vda1       25226960 3900712  21309864  16% /

Display Inode Usage

In Linux file system, an inode is a data structure which holds the information about a file or directory like its size, owner, device node, socket, pipe, etc.

Use the -i option with df command to get information about the filesystem inodes usage:

df -ih /

The above command shows the infomation about the inodes on the file system mounted to system root directory / in human-readable format.

Filesystem     Inodes IUsed IFree IUse% Mounted on
/dev/vda1        3.1M  144K  3.0M    5% /

When you use -i option, it shows the following columns:

Output format

You can also customize the output of the df command. Use the --output[=FIELD_LIST] option, to specify the fields which you wants to be show in the output. You should give the field list with comma-separated. Following are the valid field names:

For example, to show the information of all ext4 partition with only filesystem name, size and the percentage of used space, type:

df -h -t ext4 --output=source,size,pcent
Filesystem      Size Use%
/dev/vda1        25G  16%

Conclusion

In this guide, you learned how to use the df command to get the information about filesystem disk space usage. To learn more about df command options, type man df in your terminal.

If you have any questions, please leave a comment below.

Exit mobile version