How to Use the df Command in Linux

How to Use the df Command in Linux

The df command in Linux is a powerful utility used to check disk space usage on a system. It provides a quick overview of available and used space on all mounted file systems. Whether you are a system administrator, developer, or Linux enthusiast, understanding how to use the df command in Linux is essential for monitoring storage and ensuring smooth system operations.

In this guide, we will explore the syntax, basic and advanced usage, key options, and common troubleshooting techniques for the df command. Additionally, we will address frequently asked questions to provide a comprehensive understanding of this essential tool.

Click here to find the latest list of How to Use the df Command in Linux

Understanding the Basic Syntax

The basic syntax of the df command is as follows:

 df [options] [file or filesystem]        

Parameters:

  • file or filesystem: Specifies the particular file or file system whose disk usage is to be displayed.
  • options: Modifies the command output to display specific details.

Example Usage:

To check disk usage in a human-readable format, use:

 df -h        

This command presents output in a user-friendly format with sizes in KB, MB, GB, or TB instead of default block sizes.

Also Read:- How to Move a File in Linux Like a Pro using mv Command

How to Check Disk Space Using the df Command

Checking All Mounted File Systems

To view disk space usage of all mounted file systems, simply run:

 df        

Checking a Specific File System

To check disk space usage of a specific directory or file system, specify its mount point. For example, to check /home:

 df /home        

Displaying Sizes in Human-Readable Format

To display file system sizes in KB, MB, or GB instead of blocks:

 df -h        

Understanding df Command Output

Running df -h typically displays output like this:

Filesystem      Size  Used Avail Use% Mounted on
/dev/sda1       50G   20G   30G   40%  /
tmpfs          500M  100K  499M    1%  /run
devtmpfs       1.9G     0  1.9G    0%  /dev        

Explanation of Columns:

  • Filesystem: Name of the storage device or partition.
  • Size: Total size of the file system.
  • Used: Space currently in use.
  • Avail: Available space for use.
  • Use%: Percentage of disk usage.
  • Mounted on: Directory where the file system is mounted.

Click here to find the latest list of How to Move a File in Linux Like a Pro using mv Command

Using Options with the df Command

The df command provides several options to customize the output:

-h: Human-Readable Format

 df -h        

Displays sizes in KB, MB, GB, or TB for better readability.

-T: Show File System Type

 df -T        

Displays an additional column showing the type of file system (e.g., ext4, xfs, tmpfs).

-i: Show Inode Usage

 df -i        

Displays inode usage instead of block usage, useful for diagnosing inode exhaustion.

-P: POSIX Format

 df -P        

Displays output in a standardized, more script-friendly format.

Advanced df Command Usage

Checking Disk Space for Specific File Types

Use the df -t option to filter file systems of a specific type:

 df -t ext4        

Using df with grep for Filtering Results

To check only the root partition:

 df -h | grep '/$'        

Automating Disk Usage Monitoring with Scripts

Create a script to check disk space and alert if usage exceeds a threshold:

#!/bin/bash
THRESHOLD=80
USAGE=$(df -h | awk 'NR>1 {print $5 " " $6}' | sed 's/%//g')

while read output; do
  use=$(echo $output | awk '{print $1}')
  partition=$(echo $output | awk '{print $2}')
  if [ $use -ge $THRESHOLD ]; then
    echo "Warning: $partition usage is at ${use}%!"
  fi
done <<< "$USAGE"        

Save this script as check_disk_usage.sh and execute it periodically to monitor disk space.

FAQs

What is the df command used for in Linux?

The df command is used to check disk space usage on Linux systems. It displays the available and used space of all mounted file systems.

How do I check free space using the df command?

Use:

 df -h        

This command shows available space in a human-readable format.

What is the difference between df -h and df -T?

  • df -h displays disk space usage in KB, MB, or GB.
  • df -T adds a column showing the file system type (e.g., ext4, tmpfs).

How can I check inode usage with df?

To check inode usage, use:

 df -i        

This is useful when dealing with a high number of small files that may exhaust available inodes before running out of disk space.

Why does df show different values from du?

  • df reports disk space usage from the file system’s perspective.
  • du (disk usage) calculates space used by files in a directory.
  • Differences arise due to deleted but still open files or reserved space for system use.

Conclusion

The df command in Linux is an essential tool for monitoring and managing disk space usage. Whether you need to check available storage, monitor inode usage, or filter results, understanding how to use df effectively can help you maintain a healthy system.

Now that you have a complete guide, try these commands on your system and explore the various options available. If you have any questions or tips, feel free to share them below! 🚀

To view or add a comment, sign in

More articles by Vivek Yadav

  • How to Make Pictures Talk

    How to Make Pictures Talk has become one of the most searched topics in 2026 as AI Avatar technology continues to…

  • Create Talking Avatar From Photo

    Create Talking Avatar From Photo is one of the most in-demand AI capabilities in 2026, allowing users to turn a simple…

  • How to Make a Talking Picture

    How to Make a Talking Picture is becoming one of the most searched topics in 2026 as AI Avatar technology continues to…

  • How to Replace Face In Video

    Understanding How to Replace Face In Video has become an important part of modern AI content creation in 2026. With…

  • Create AI Image to Video with Audio and Emotions

    The ability to Create AI Image to Video with Audio and Emotions has become one of the most powerful trends in 2026…

  • Make an Image Talk

    The demand for Make an Image Talk tools has surged in 2026 as artificial intelligence continues to simplify video…

  • AI Talking Photo Generator

    The AI Talking Photo Generator tools in 2026 are advanced AI-powered platforms that transform static images into…

  • AI Make Pictures Talk

    AI Make Pictures Talk tools in 2026 are transforming static images into dynamic, speaking visuals using advanced…

  • Talking Pictures App

    A Talking Pictures App is an AI-powered solution that transforms static images into animated videos where the subject…

  • Talking Photos AI Free

    Best Talking Photos AI Free tools are AI-powered platforms that allow users to animate static images and make them…

Others also viewed

Explore content categories