Learn about df command in Linux

Learn about the df command in Linux.

The df command in Linux is used to display information about disk space usage on a file system. It shows how much disk space is used and available on file systems. This helps you see how much storage capacity your system’s devices have and how much is being used. Here’s a detailed explanation of how the df command works:

Syntax:

df [OPTION]... [FILE]...

Options:

  • -h, --human-readable: Print sizes in a human-readable format (e.g., KB, MB, GB, etc.).
  • -H, --si: Use powers of 1000 instead of 1024 for human-readable output.
  • -T, --print-type: Print file system type as well.
  • -t, --type=TYPE: Limit listing to file systems of specified types (e.g., ext4, nfs, tmpfs, etc.).
  • -x, --exclude-type=TYPE: Exclude file systems of specified types.
  • --total: Display a total summary at the end.
  • --help: Display help message and exit.
  • --version: Display version information and exit.

Usage:

  1. Basic Usage:
    Running df without any options or arguments will display disk space information for all mounted file systems in the default format (in 1 KB blocks):
   $ df
   Filesystem     1K-blocks    Used Available Use% Mounted on
   /dev/sda1       102384720 2298164  95296656   3% /
   tmpfs            1024564    3136   1021428   1% /dev/shm
   /dev/sdb1       51767268 2541260  46432892   6% /mnt/data
  1. Human-Readable Output:
    You can use the -h or --human-readable option to display sizes in a more human-readable format:
   $ df -h
   Filesystem      Size  Used Avail Use% Mounted on
   /dev/sda1        98G  2.2G   91G   3% /
   tmpfs           1000M  3.1M  997M   1% /dev/shm
   /dev/sdb1        49G  2.5G   44G   6% /mnt/data
  1. Total Disk Space:
    Adding the --total option will display a summary line at the end with the total disk space usage:
   $ df -h --total
   Filesystem      Size  Used Avail Use% Mounted on
   /dev/sda1        98G  2.2G   91G   3% /
   tmpfs           1000M  3.1M  997M   1% /dev/shm
   /dev/sdb1        49G  2.5G   44G   6% /mnt/data
   Total            148G  4.8G  135G   4%
  1. Limiting Display to Specific File System Types:
    You can use the -t option followed by a comma-separated list of file system types to limit the display to only specific types:
   $ df -h -t ext4
   Filesystem      Size  Used Avail Use% Mounted on
   /dev/sda1        98G  2.2G   91G   3% /
   /dev/sdb1        49G  2.5G   44G   6% /mnt/data
  1. Displaying File System Type:
    Use the -T option to display the file system type along with the other information:
   $ df -h -T
   Filesystem     Type      Size  Used Avail Use% Mounted on
   /dev/sda1      ext4       98G  2.2G   91G   3% /
   tmpfs          tmpfs    1000M  3.1M  997M   1% /dev/shm
   /dev/sdb1      ext4       49G  2.5G   44G   6% /mnt/data
  1. Excluding File System Types:
    The -x option followed by a comma-separated list of file system types allows you to exclude specific types from the display:
   $ df -h -x tmpfs
   Filesystem     Size  Used Avail Use% Mounted on
   /dev/sda1       98G  2.2G   91G   3% /
   /dev/sdb1       49G  2.5G   44G   6% /mnt/data
  1. Displaying Information for Specific Files or Directories:
    You can provide one or more file or directory paths as arguments to the df command to display information about the file system containing those paths:
   $ df -h /home/user /mnt/data
   Filesystem      Size  Used Avail Use% Mounted on
   /dev/sda1        98G  2.2G   91G   3% /
   /dev/sdb1        49G  2.5G   44G   6% /mnt/data

These are some of the common use cases and options for the df command in Linux. It provides valuable information about disk space usage that can be helpful for system monitoring, capacity planning, and troubleshooting storage-related issues.

Leave a Comment

Scroll to Top