Open In App

df command in Linux with Examples

Last Updated : 14 Dec, 2023
Improve
Improve
Like Article
Like
Save
Share
Report

Ever felt the chilling fear of a “disk full” error message on your Linux machine? Fear not, for the mighty df command stands ready to guide you through the treacherous terrain of disk space management! This article delves deep into the df command, equipping you with the knowledge and skills to navigate your storage with confidence.

What is df Command in Linux?

disk free also known as `df`, which is a powerful utility that provides valuable information on disk space utilization. The df command displays information about file system disk space usage on the mounted file system. This command retrieves the information from `/proc/mounts` or `/etc/mtab`. By default, df command shows disk space in Kilobytes (KB) and uses the SI unit suffixes (e.g, M for megabytes, G for gigabytes) for clarity.

Syntax of `df` command in Linux

The basic syntax of df is:

df [options] [filesystems]

Here,

  • options: These are optional flags that modify the output of the command. We’ll discuss some important ones later.
  • filesystems: You can specify specific filesystems (mount points) to check their usage instead of getting information for all mounted drives.

If no file name is given, it displays the space available on all currently mounted file systems.

For example:

df

This will display information about all the mounted file systems which will include total size, used space, usage percentage, and the mount point.

df

df

This command displays a table with columns for:

  • Filesystem: The name of the mounted storage device (e.g., /dev/sda4).
  • Size: The total size of the filesystem in bytes.
  • Used: The amount of space currently occupied by data in bytes.
  • Avail: The amount of free space available in bytes.
  • Use%: The percentage of the filesystem used.
  • Mounted on: The directory where the filesystem is mounted (e.g., //home).

Now, if you specify a particular file, then it will show the mount information of that particular file.

For example:

df jayesh.txt

df jayesh.txt

You can replace `jayesh.txt` with the desired file name 

Options Available in `df` command in Linux

Options Description
‘-a’ or ‘–all’ Includes pseudo, duplicate, and inaccessible file systems in the output.
‘-B <SIZE>’ or ‘–block-size=<SIZE>’ Scales sizes by SIZE before printing them.
‘-h’ or ‘–human-readable’ Prints sizes in a human-readable format using power of 1024.
‘-H’ or ‘–si’ Prints sizes in a human-readable format using power of 1000.
‘-i’ or ‘–inodes’ Lists inode information instead of block usage.
‘-l’ or ‘–local’ Limits listing to local file systems.
‘-P’ or ‘–portability’ Uses POSIX output format for better portability.
‘–sync’ Invokes sync before getting usage info.
‘–total’ Elides all entries insignificant to available space and produces a grand total.
‘-t <TYPE>’ or ‘–type=<TYPE>’ Limits listing to file systems of type TYPE.
‘-T’ or ‘–print-type’ Prints file system type

Usage and Implementation of df command in Linux

`-a` option in `df` command in Linux

If you want to display all the file system, use -a option.

df -a
df -a

df -a

`-h` or `-H` option in `df` command in Linux

Use -h option to display size in power of 1024

df -h jayesh.txt
df -h jayesh.txt

df -h jayesh.txt

Use -H option to display sizes in power of 1000

df -H jayesh.txt
df -H jayesh.txt

df -H jayesh.txt

`–total` option in `df` command in Linux

To get complete grand total, use –total option

df --total
df --total

df –total

`-T` option in `df` command in Linux.

Use -T option to display file type 

For example:

df -T jayesh.txt
df -T jayesh.txt

df -T jayesh.txt

You can see the file type for `jayesh.txt` is ext4

`–help` option in `df` command in Linux

And for more help, you can use –help option.

df --help
df --help

df –help

`-x` option in `df` command in Linux

Exclude specific file system types from the output

For Example: tmpfs

df -x tmpfs
df -x tmpfs

df -x tmpfs

Frequelty Asked Question

1. What is the df command in Linux, and what does it do?

The `df` command is a Linux utility that is used to display information about the disk space usage on a file system. It shows details such as total disk space, used space, available space, and the percentage of usage for each mounted file system.

2. How do I use the df command to display disk space information for a specific file system?

To display disk space information for a specific file system, you can use the `-h` option for human-readable output and specify the file system path as an argument. For example:

df -h /dev/sda1

3. Can the df command display disk space information in a specific format or units?

Yes, the df command provides options to display disk space information in different formats. The -h option, as mentioned earlier, displays sizes in a human-readable format (e.g., KB, MB, GB). Additionally, you can use options like -k (kilobytes), -m (megabytes), and -g (gigabytes) to customize the output.

4. How can I sort the df output to see the file systems with the most or least disk space usage?

You can use the `--sort` option with the `df` command to sort the output based on specific columns. For example, to sort by the percentage of disk space usage in descending order, you can use the command:

df --sort=-p

5. Is there a way to exclude certain file systems from the df command output?

Yes, you can use the -x option followed by a list of file system types to exclude from the output. For instance, to exclude the tmpfs file system, you can use:

df -x tmpfs

Conclusion

In this article we have discussed `df` command which is a powerful tool for monitoring disk space usage on Linux System. By understanding its options that we have discussed and using them effectively to get useful information like file system usage, identify potential storage constraints and make informed decisions regarding resource allocation and management. 



Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads