Linux df Command

In the realm of Linux and Unix-like operating systems, efficient disk space management is a crucial aspect of system administration. The df command is a powerful tool that provides essential insights into disk space usage, allowing users and administrators to monitor storage availability, identify space-hogging directories, and plan for storage upgrades. In this blog post, we will explore the df command in depth, covering its syntax, options, and various practical applications.

Basic Syntax

The basic syntax of the df command is simple:

bash
df options filesystem
  • options: Additional flags that modify the behavior of the df command.
  • filesystem: The name of the filesystem to display information for. If omitted, it displays information for all mounted filesystems.

Displaying Disk Space Usage

To display disk space usage for all mounted filesystems, you can use the df command without any options.

bash
df

This will display information about each mounted filesystem, including the device, total space, used space, available space, percentage of usage, and the mount point.

Human-Readable Output

The -h or --human-readable option makes the output more human-readable by displaying sizes in a human-readable format (e.g., KB, MB, GB).

bash
df -h

Displaying Filesystem Type

The -T or --print-type option displays the filesystem type for each filesystem.

bash
df -T

Excluding Specific Filesystems

The --exclude-type option allows you to exclude specific filesystem types from the output.

bash
df --exclude-type=tmpfs

This will exclude tmpfs filesystems from the output.

Practical Applications

  1. Viewing Disk Space Usage:

    bash
    df
  2. Displaying Human-Readable Output:

    bash
    df -h
  3. Excluding Specific Filesystem Types:

    bash
    df --exclude-type=tmpfs

Advanced Usage

Displaying Inodes

The -i or --inodes option displays inode information for each filesystem, including the total inodes and used inodes.

bash
df -i

Displaying a Specific Filesystem

To display information for a specific filesystem, specify its name as an argument.

bash
df /dev/sda1

Monitoring Disk Space

You can use the watch command to continuously monitor disk space usage at a regular interval.

bash
watch -n 10 df -h

This will display disk space usage every 10 seconds.