df Command in Linux

df-Command-in-Linux-Feature-Image.png

In Linux, monitoring disk space usage is an important task for system administrators and users. So, there should be a way to find the amount of disk space used and available on all mounted file systems. The df command in Linux is used to determine how much disk space is used and available on the filesystem. In this guide, we will learn about the df command in Linux with all the key options used with it.

Table of Contents:

What is the df Command in Linux?

The df command in Linux stands for Disk Free, and is used to analyze disk space utilized on the file systems and how much space is used, available, and the total size of the file system on your system. The main purpose of the df command in Linux is to understand how different partitions are utilized by the users and administrators, and monitor and manage the disk to prevent storage issues.

Syntax of the df Command in Linux

Below is the syntax of the df command in Linux:

df [options] [file]

In the above syntax,

  • file shows the usage of the file system
  • options are used to modify the output format or to show additional details

Below is a simple example of the df command.

example of the df command.
Master DevOps Today - Accelerate Your Future
Enroll Now and Transform Your Future
quiz-icon

In the above example, let us understand the 1st row

  • Filesystem refers to the name of the disk or memory area.
  • 1K-blocks are the total size of the disk or the area in 1K blocks.
  • Used refers to how much space has already been used.
  • Available is the free space.
  • Use% is the amount of space used as a percentage.
  • Mounted on means that the storage (like a hard disk, USB, or virtual memory) is connected to the Linux file system.
example of the df command2

Options Available in the df Command in Linux

Many options can be used with the df command, depending on the requirement. Some of them are:

1. Display All the File Systems

The df command in Linux hides many file systems to keep the output simple for users, but the df -a command in Linux displays all the file systems present in the system, i.e.,

  • Hidden or system file systems
  • File systems that have 0 blocks
  • Pseudo or virtual file systems (not real disks)

It is helpful when you want to troubleshoot your system and learn how Linux manages memory and devices.

Below is the syntax of it:

df -a

Example:

Display All the File Systems

In the above example, the files with 0 blocks are also displayed along with the files and directories with spaces.

2. Display Disk Space Information in a Human-Readable Format

To view disk space usage in a format that is easy to read, use the -h option with the df command in Linux. It automatically converts raw bytes into the most appropriate unit, KB, MB, or GB, to make it easier for the user to read.

Below is the syntax of it:

df -h

Example:

 Display Disk Space Information in a Human

In the above example, the df -h command gives the 1st row in a human-readable form, i.e., 1K-blocks is changed to the Size column.

3. Check Disk Space Usage of /home Directory

To check how much space is used on the disk/partition, you can use /home with the df command in Linux. It tells you about the filesystem where /home resides, and is useful when you want to know if your disk is getting full.

Below is the syntax of it:

df /home

Example:

 Check Disk Space Usage

The command df /home displays the details of the home folder.

4. Display Disk Space Information for a Specific File System

To view the disk usage for a specific file system, you just have to pass the path as an argument to the df command.

Below is the syntax of it:

df -h /path/to/mount/point

Example:

Display Disk Space Information for a Specific File System

The command df -h /home/akshat/intellipaat is the path to the directory intellipaat, and below it is the storage information.

5. Display Disk Space Information in a Specific Format or Units

By default, the df command in Linux shows how much disk space is used and available on our file system in 1K-blocks, which can be hard to read, and you need that information in terms of GB or MB.

Some options can be used with the df command to get the expected output in human-readable form, i.e., in MB or GB

If you want the disk space to be visible in GB, you can use the following command,

df --block-size=1G

Example:

 Display Disk Space Information in a Specific Format or Units

In the above command, first the disk space is displayed as default, and then in terms of GB.

Further, the following table will help you get your disk space as needed.

Task Command
Auto units (MB, GB, TB) df -h
MB df –block-size=1M
GB df –block-size=1G
KB df –block-size=1K
Bytes df –block-size=1
All file systems (incl. 0 blocks) df -a
Inodes instead of block usage df -i
Output in POSIX format df -P
Specific filesystem type df -t ext4
Exclude a filesystem type df -x tmpfs
Human-readable + filesystem info df -Th
Specific directory or file df /home
Filesystem name only df -h –output=source
Mounted on column only df -h –output=target
Used space only df -h –output=used
Custom columns (e.g., source, size, avail) df -h –output=source,size,avail

Get 100% Hike!

Master Most in Demand Skills Now!

6. Display Information About a Specific File

The df command is used to display the disk space information about a specific file by passing the file path to the df command. It shows how much space is used and available on the disk, not the size of the file itself. It is useful when you want to know if there is enough space left where the file is stored.

Below is the syntax of it:

df -h filename

Example:

Display Information About a Specific File

The above command displays the disk space usage of the filesystem where the file is present, not the file’s size.

7. Check Inode Usage in Linux

In Linux, inodes represent metadata about the files, like their permissions, owner, size, etc. Every file or directory in Linux has one inode, but if the filesystem runs out of inodes, new files cannot be created, even if disk space is available.

Below is the syntax of it:

df -i

Example:

Check Inode Usage in Linux

In the above example, inode usage is displayed.

8. Check Linux File System Type

To find out the type of file system used by your partitions for storage, you can use the -T option with the df command.

Below is the syntax of it:

df -T

Example:

Check Linux File System Type

The above command, df -T, lists the type of filesystem used as storage.

9. Display a Total of All Disks

The –total option with the df command is used to display the total of all disk space usage statistics listed in the output. It is helpful when you want to summarize total disk usage across all or a specific file.

Below is the syntax of it:

df --total

Example:

Display a Total of All Disks

In the above example, the total space utilized by the disk is displayed.

Note: Above, we have used the df –total command with the -h option to get human-readable output.

10. Display All Options and their Descriptions

The –help option is used with the df command to display a summary of all available options with their descriptions. It provides a quick reference guide in your terminal.

Below is the syntax of it:

df --help

Example:

Display All Options and their Descriptions

In the above example, all the key options of the df command are displayed.

11. Exclude the Filesystem of a Specific Type

The -x or –exclude-type option with the df command in Linux is used to exclude file systems of a specific type from the output. It is useful when you want to ignore filesystems like tmpfs (Temporary File System), devtmpfs (Device Temporary File System), etc., and focus only on important file systems.

Below is the syntax of it:

df -x

Example:

Exclude the Filesystem of a Specific Type

In the above example, the filesystem of tmpfs is excluded from the output.

The du command in Linux

The du command in Linux is used to estimate and display the amount of disk space used by files and directories, and helps you track which files or folders are consuming the most space on your system.

It has the following syntax:

du [OPTIONS] [FILE/DIRECTORY...]

In the above syntax,

  • options are used to modify the output format or to show additional details
  • file or directory is the target file or directory you want to analyze.

Difference Between df and du Commands

Below are the differences between the df and du commands

Feature df Command du Command
Full Form Disk Free Disk Usage
Purpose Shows available and used disk space on mounted file systems Shows disk space used by specific files/directories
Level of Information File system-level summary File or directory-level detailed usage
Default Target All mounted file systems Current directory (.)
Typical Use Case Check the overall disk space on partitions Find out what is consuming space inside a folder
Unlock Your Future in Linux
Start Your Linux Journey Today
quiz-icon

Conclusion

From the above article, we concluded that the df command in Linux is a powerful tool that helps users and system administrators monitor and manage disk space effectively. It can be used to display the result in a human-readable format, check inodes, identify filesystem types, or exclude virtual filesystems as per the needs of the user. A similar command to df is the du command, which is used to display the amount of disk space used by files and directories. These two commands serve different purposes based on the needs, hence they should be used appropriately.

If you want to learn more about the df command in Linux, you can refer to our Linux Course, which will help you gain hands-on, practical experience.

df Command in Linux – FAQs

Q1. What is df in Linux?

In Linux, df stands for “disk free”. It’s a command-line utility used to display information about disk space usage on file systems.

Q2. How to check disk space in Linux command?

To check disk space in Linux, the primary used command is df, which stands for “disk free”.

Q3. What is the difference between du and df?

The du command tells files and directories disk usage, and the df command shows how much disk space your filesystem is using.

Q4. How to check the disk in Linux?

To check disk usage in Linux, the df command is used to display information about disk space usage.

Q5. What are the units of df in Linux?

df measures space in 1K blocks by default, but this can be changed using options like –block-size.

About the Author

Senior Consultant Analytics & Data Science, Eli Lilly and Company

Sahil Mattoo, a Senior Software Engineer at Eli Lilly and Company, is an accomplished professional with 14 years of experience in languages such as Java, Python, and JavaScript. Sahil has a strong foundation in system architecture, database management, and API integration. 

fullstack