Oct 21, 2023 5 min read

Df Command in Linux (Check Disk Space)

Use df command in Linux with our step-by-step tutorial. The df command is used to display disk space usage information for file systems.

Df Command in Linux
Table of Contents

Introduction

Before we discuss Df command in Linux (Check Disk Space), let's first understand-What is df Command ?

The df command in Linux is used to display disk space usage information for file systems. It provides details about the total, used, and available space on mounted file systems, helping users monitor disk utilization and identify potential storage issues. The df command also displays the file system type and the mount point of each file system.

You may get a thorough report on the system's disc space consumption with the df command on Linux and Unix platforms in this tutorial. We will also address a few FAQs on Df Command in Linux (Check Disk Space).

Using the df Command

The df command has the following general syntax:

df [OPTIONS]... FILESYSTEM...

The df command, when run without any arguments, displays information about all mounted file systems:

df
Output

Filesystem     1K-blocks      Used Available Use% Mounted on
dev              8172848         0   8172848   0% /dev
run              8218640      1696   8216944   1% /run
/dev/nvme0n1p3 222284728 183057872  27865672  87% /
tmpfs            8218640    150256   8068384   2% /dev/shm
tmpfs            8218640         0   8218640   0% /sys/fs/cgroup
tmpfs            8218640        24   8218616   1% /tmp
/dev/nvme0n1p1    523248    107912    415336  21% /boot
/dev/sda1      480588496 172832632 283320260  38% /data
tmpfs            1643728        40   1643688   1% /run/user/1000

The columns on each line are as follows:

  • "Filesystem" - Name of the file system.
  • "1K-blocks" – The file system's size in 1K blocks.
  • "Used" - Refers to the amount of space that has been used in 1K blocks.
  • "Available" - The amount of space available in 1K blocks.
  • "Use%" - Percentage of space that has been utilized.
  • "Mounted on" - The directory on which it is mounted.

Pass the name or mount point of a file system to the df command to display information for that file system exclusively.

You can run df /dev/nvme0n1p3 or df / to see the space available on the file system mounted to the system root directory (/).

df /
Output

Filesystem     1K-blocks      Used Available Use% Mounted on
/dev/nvme0n1p3 222284728 183057872  27865672  87% /

Display Disk Space Usage in a Human-Comprehensible Format

The df program displays disc space in 1-kilobyte blocks by default, as well as the size of used and available disc space in kilobytes.

Invoke the df program with the -h option to display information about disc devices in human-readable format (kilobytes, megabytes, gigabytes, and so on):

df -h
Output

Filesystem      Size  Used Avail Use% Mounted on
dev             7.8G     0  7.8G   0% /dev
run             7.9G  1.8M  7.9G   1% /run
/dev/nvme0n1p3  212G  176G   27G  88% /
tmpfs           7.9G  145M  7.7G   2% /dev/shm
tmpfs           7.9G     0  7.9G   0% /sys/fs/cgroup
tmpfs           7.9G   24K  7.9G   1% /tmp
/dev/nvme0n1p1  511M  106M  406M  21% /boot
/dev/sda1       459G  165G  271G  38% /data
tmpfs           1.6G   16K  1.6G   1% /run/user/1000

File System Types

The -T option instructs df to show the following file system types:

df -T

An additional column named "Type" appears in the output, indicating the file system type:

Output

Filesystem     Type     1K-blocks      Used Available Use% Mounted on
dev            devtmpfs   8172848         0   8172848   0% /dev
run            tmpfs      8218640      1744   8216896   1% /run
/dev/nvme0n1p3 ext4     222284728 183666100  27257444  88% /
tmpfs          tmpfs      8218640    383076   7835564   5% /dev/shm
tmpfs          tmpfs      8218640         0   8218640   0% /sys/fs/cgroup
tmpfs          tmpfs      8218640        24   8218616   1% /tmp
/dev/nvme0n1p1 vfat        523248    107912    415336  21% /boot
/dev/sda1      ext4     480588496 172832632 283320260  38% /data
tmpfs          tmpfs      1643728        40   1643688   1% /run/user/1000

Use the -t option followed by the type to limit the list to file systems of a specified type.

An example of how to list all ext4 partitions is as follows:

df -t ext4
Output

Filesystem     1K-blocks      Used Available Use% Mounted on
/dev/nvme0n1p3 222284728 183666112  27257432  88% /
/dev/sda1      480588496 172832632 283320260  38% /data

The -x option, like the one above, lets you limit the output to file systems that aren't of a specified type:

df -x tmpfs
Output

Filesystem     1K-blocks      Used Available Use% Mounted on
dev              8172848         0   8172848   0% /dev
run              8218640      1696   8216944   1% /run
/dev/nvme0n1p3 222284728 183057872  27865672  87% /
/dev/nvme0n1p1    523248    107912    415336  21% /boot
/dev/sda1      480588496 172832632 283320260  38% /data

Display Inode Usage

In Unix and Linux file systems, an inode is a data structure that includes information about a file or directory. This includes size, owner, device node, socket, pipe, and so on, with the exception of da.

The df command shows information about the file system inodes used when used with the -i option.

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

df -ih /
Output

Filesystem     Inodes IUsed IFree IUse% Mounted on
/dev/nvme0n1p3    14M  1.9M   12M   14% /

When the -i option is used, the following columns are included in each line of the output:

  • "Filesystem" - Name of the file system.
  • "Inodes" - The entire number of inodes on the file system.
  • "IUsed" - Denotes the number of inodes that have been used.
  • "IFree" - Refers to the number of free (unused) inodes in the system.
  • "IUse percent" - It is the percentage of nodes that have been used.
  • "Mounted on" - The directory on which it is mounted.

Output Format

You can also change the output format with the df command.

Use the --output[=FIELD LIST] option to indicate which fields should be displayed in the command output.

A comma-separated list of columns to include in the output is FIELD_LIST. Each field can only be used once. The following are valid field names:

  • source - The source of the File System.
  • fstype - Type of the file system.
  • itotal - Total number of inodes.
  • iused - The number of inodes that have been used.
  • iavail - The number of inodes that are available.
  • ipcent - Inode usage percentage.
  • size - Total amount of disc space available.
  • used - Disk space that has been utilized.
  • avail - Disk space that is available.
  • pcent - Percentage of used space.
  • file - File name if it is specified on the command line.
  • target - The mount point.

For example, to display the output of all ext4 partitions in a human-readable format with only the file system name, size, and % of used space, you may run the following command:

df -h -t ext4 --output=source,size,pcent
Output

Filesystem      Size Use%
/dev/nvme0n1p3  212G  88%
/dev/sda1       459G  38%

FAQs on Df Command in Linux

How does the df command work?

df gathers disk space usage information by querying the file systems currently mounted on the system.

How do I use the df command to check disk space usage?

To use df, simply execute the df command without any arguments. It will display disk space usage information for all mounted file systems.

Can I display disk space usage in a more human-readable format?

Yes, you can use the -h or --human-readable option with df to display sizes in a more understandable format using units like K, M, G, etc. For example, df -h will display disk space usage in human-readable format.

Can df show disk space usage for a specific file system?

Yes, you can specify a particular file system with the df command. For example, df /dev/sda1 will display information about the disk space usage for the file system mounted at /dev/sda1.

Can I sort the output of df by disk usage?

By default, df does not provide options to sort its output. However, you can use tools like sort or awk in combination with df to sort disk space usage information based on specific criteria if required.

What is the difference between df and du?

While df displays information about disk space usage on mounted file systems, du estimates the disk space utilized by specific files and directories. df provides information on the file system level, whereas du provides a more granular analysis at the file or directory level.

Can df display disk space usage for network file systems (NFS, SMB, etc.)?

Yes, df can display disk space usage for network file systems that are mounted on the system. It will provide information about the space utilization on the network file system as if it were a local file system.

Conclusion

You have learned to get a report on the file-system's disc space consumption with the df command. Type man df in your terminal to see all the df command's options.

Use the du command to find out how much disc space files and folders are using up.

If you have any queries, please leave a comment below and we’ll be happy to respond to them.

Great! You’ve successfully signed up.
Welcome back! You've successfully signed in.
You've successfully subscribed to DevOps Tutorials - VegaStack.
Your link has expired.
Success! Check your email for magic link to sign-in.
Success! Your billing info has been updated.
Your billing was not updated.