linux df

How to Use linux df Command to Check Disk Space

Managing disk space is an important task for every Linux user. Without proper monitoring, systems can run out of storage. This can cause crashes, data loss, or poor performance. Thankfully, Linux provides a simple command to handle this task. The Linux df command helps check disk space clearly and easily.

In this guide, we will explore how to use this command. We will cover its basic use, options, and examples. The article is written in simple wording for beginners.

What is the df Command in Linux?

The df command stands for disk free. It shows the amount of space used and available on file systems. This command helps monitor storage quickly.

Every Linux system comes with the df utility. It is available by default and requires no installation. System administrators often use it to track space on partitions and drives.

Basic Syntax of Linux df

The basic syntax of the Linux df command is:

df [options] [file]
  • df Shows disk space details of mounted file systems.
  • options allow customization of output.
  • file specifies a particular file or directory to check.

Example: Running df Without Options

If you type the following in your terminal:

df

You will see output like this:

Filesystem     1K-blocks     Used Available Use% Mounted on
/dev/sda1      488281250 12000000 460000000   3% /
tmpfs           16384000        0  16384000   0% /dev/shm

Here is what each column means:

  • Filesystem: Name of the device or partition.
  • 1K-blocks: Total space in 1K blocks.
  • Used: Space already used.
  • Available: Free space available.
  • Use%: Percentage of space used.
  • Mounted on: Mount point of the filesystem.

Using df with Human-Readable Output

By default, df shows space in 1K blocks. This can be hard to read. Use the -h option to display human-readable values.

Example:

df -h

Output:

Filesystem      Size  Used Avail Use% Mounted on
/dev/sda1       465G   12G  440G   3% /
tmpfs            16G     0   16G   0% /dev/shm

Here, disk space is shown in GB or MB, which is easier to understand.

Checking a Specific Filesystem

You can use df to check a specific directory or file.

Example:

df -h /home

This will display disk usage only for the /home directory.

Displaying Inodes with df

Apart from space, Linux uses inodes to store file information. Inodes can also run out, even if space remains. Use the -i option to view inode usage.

Example:

df -i

Output:

Filesystem     Inodes  IUsed   IFree IUse% Mounted on
/dev/sda1     3200000  50000 3150000    2% /

Checking File System Types

The -T option shows the type of each filesystem.

Example:

df -T

Output:

Filesystem     Type   1K-blocks     Used Available Use% Mounted on
/dev/sda1      ext4   488281250 12000000 460000000   3% /

This shows that the root filesystem is of type ext4.

Excluding Certain Filesystems

Sometimes you may want to exclude temporary filesystems. Use the -x option to exclude a type.

Example:

df -x tmpfs -h

This excludes tmpfs from the result.

Showing All Filesystems

Some filesystems are hidden by default. Use the -a option to display them.

Example:

df -a

This will include special and dummy filesystems in the output.

Combining Options for Better Results

You can combine options for detailed output.

Example:

df -hT

This shows disk space with human-readable sizes and filesystem types.

Real-Life Use Cases of Linux df

  1. Monitoring server storage: Admins use df to prevent full partitions.
  2. Checking space before installing software: Ensures there is enough room.
  3. Managing backups: Helps decide where to store files.
  4. Debugging disk errors: Verifies if space issues cause problems.

Common Errors with df

  • If a partition is 100% full, df will show Use% = 100.
  • If a disk is unmounted, df will not display it.
  • Running df without permissions may show limited results. Use sudo df -h for full details.

Conclusion

The Linux df command is a simple but powerful tool. It helps track and manage disk usage effectively. With options like -h, -T, and -i, you can get detailed insights.

Every Linux user should know this command. It ensures smooth performance and prevents disk-related issues.

By practicing the examples above, you can master disk space monitoring. Next time your system slows down, run df and check the space.