How to use df command.

How To Use Df Command.

In this article we will show you how to check disk space with df command.

 

Using the df Command

The general syntax for the df command is as follows:

df [OPTIONS]... FILESYSTEM...

When used without any argument, the df command will display information about all mounted file systems :

df
Filesystem     1K-blocks    Used Available Use% Mounted on
devtmpfs         2961576       0   2961576   0% /dev
tmpfs            2971804       0   2971804   0% /dev/shm
tmpfs            2971804  262624   2709180   9% /run
tmpfs            2971804       0   2971804   0% /sys/fs/cgroup
/dev/vda1       23753096 1862316  20666232   9% /
tmpfs             594364       0    594364   0% /run/user/0

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.

To display information only for a specific file system, pass its name or the mount point to the df command.

For example, to show the space available on the file system mounted to the system root directory (/), you can use either df /dev/nvme0n1p3 or df /.

df /
Filesystem     1K-blocks    Used Available Use% Mounted on
/dev/vda1       23753096 1862316  20666232   9% /

 

Show Disk Space Usage in Human Readable Format

By default, the df command shows the disk space in 1-kilobyte blocks and the size of used and available disk space in kilobytes.

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

df -h
Filesystem      Size  Used Avail Use% Mounted on
devtmpfs        2.9G     0  2.9G   0% /dev
tmpfs           2.9G     0  2.9G   0% /dev/shm
tmpfs           2.9G  257M  2.6G   9% /run
tmpfs           2.9G     0  2.9G   0% /sys/fs/cgroup
/dev/vda1        23G  1.8G   20G   9% /
tmpfs           581M     0  581M   0% /run/user/0

 

File System Types

The -T option tells df to display file system types:

df -t

If you want to limit listing to file systems of a specific type use the -t option followed by the type.

Here is an example showing how to list all ext4 partitions:

df -t ext4

Similar to above, the -x option allows you to limit the output to file systems that are not of a specific type:

df -x tmpfs
Filesystem     1K-blocks    Used Available Use% Mounted on
devtmpfs         2961576       0   2961576   0% /dev
/dev/vda1       23753096 1862336  20666212   9% /

 

Display Inode Usage

An inode is a data structure in Unix and Linux file systems, which contains information about a file or directory such as its size, owner, device node, socket, pipe, etc., except da.

When invoked with the -i option, the df command prints information about the filesystem inodes usage.

The command below will show information about the inodes on the file system mounted to system root directory / in human-readable format:

df -ih /
Filesystem     Inodes IUsed IFree IUse% Mounted on
/dev/vda1        1.5M   34K  1.5M    3% /

When -i option is used, each line of the output includes the following columns:

  • “Filesystem” – The name of the filesystem.

  • “Inodes” – The total number of inodes on the file system.

  • “IUsed” – The number of used inodes.

  • “IFree” – The number of free (unused) inodes.

  • “IUse%” – The percentage of used inodes.

  • “Mounted on” the directory on which the filesystem is mounted.

 

Output format

The df command also allows you to customize the output format.

To specify the fields you want to be shown in the command output, use the --output[=FIELD_LIST] option.

FIELD_LIST is a comma-separated list of columns to be included in the output. Each field can be used only once. Valid field names are:

  • source – The File system source.

  • fstype – The File system type.

  • itotal – Total number of inodes.

  • iused – Number of the used inodes.

  • iavail – Number of the available inodes.

  • ipcent – Percentage of used inodes.

  • size – Total disk space.

  • used – Used disk space.

  • avail – Available disk space.

  • pcent – Percentage of used space.

  • file – The file name if specified on the command line.

  • target – The mount point.

For example, to display the output of all ext4 partition in human-readable format, showing only the filesystem name and size and the percentage of the used space you would use:

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

 

Conclusion

We’ve shown you how to use the df command to get a report of the filesystem disk space usage. To view all available df command options by typing man df in your terminal.