df Command in Linux

Topics Covered

Overview

The df command in Linux is used to display the disk space usage of file systems. It provides a snapshot of the total space, used space, available space, and the percentage of space used on each mounted file system.

Linux df Command Syntax

The syntax for the df command is as follows:

Where:

  • OPTIONS: The options or flags used to modify the behavior of the df command.
  • FILE: The file or file system for which the disk usage information is required. If not provided, df will display information for all mounted file systems.

df Command Options:

  • -a, --all: Include dummy file systems and display information for all file systems.
  • -h, --human-readable: Display sizes in a human-readable format (e.g., 1K, 234M, 2G).
  • -T, --print-type: Display the file system type.
  • -i, --inodes: Display inode information instead of block usage.

Example Usages

  • Display disk usage for all mounted file systems.:

    Output:

    Explanation: This command displays the disk usage of all mounted file systems with their respective sizes in 1K blocks.

  • Display disk usage for all file systems in human-readable format.:

    Output:

    Explanation: This command displays the disk usage of all mounted file systems with their respective sizes in a human-readable format.

Tips

  • Use the -h or --human-readable option to make the output easier to understand.

  • Combine the -T and -h options to display both the file system type and sizes in a human-readable format.

Advanced Use Cases of df Command in Linux

  • Display disk usage for a specific file or directory.:

    Output:

    Explanation: This command displays the disk usage of the file system containing the specified file or directory.

  • Display inode information for all file systems.:

    Output:

    Explanation: This command displays the inode information of all mounted file systems.

  • Display disk usage with file system type for all mounted file systems.:

    Output:

    Explanation: This command displays the disk usage of all mounted file systems along with their file system type and sizes in a human-readable format.

Conclusion

  • The df command is used to display the disk space usage of file systems.

  • It provides information about total space, used space, available space, and the percentage of space used.

  • Use the -h option to display sizes in a human-readable format.

  • The -T option displays the file system type.

  • The -i option displays inode information instead of block usage.