Header Ads

Understanding df -h: Your Guide to Checking Disk Space on Linux



If you've ever wondered how much storage space is left on your Linux system, df -h is the command you need. It's one of the most commonly used tools for monitoring disk usage, and in this post, we'll explore what it does and how to use it effectively.

What is df?

df stands for "disk free" or "disk filesystem." It reports the amount of disk space used and available on mounted filesystems. The -h flag makes the output "human-readable" by displaying sizes in KB, MB, GB, etc., instead of raw block counts.

Basic Usage

df -h

This simple command displays a table showing:

  • Filesystem: The device or partition name
  • Size: Total size of the filesystem
  • Used: Amount of space used
  • Avail: Amount of space available
  • Use%: Percentage of space used
  • Mounted on: Where the filesystem is mounted in your directory tree

Filesystem      Size  Used Avail Use% Mounted on
/dev/sda1        50G   28G   20G  59% /
/dev/sda2       100G   45G   50G  48% /home
tmpfs           7.8G  1.2M  7.8G   1% /run

Common Use Cases

Check Root Filesystem Space


df -h /

Find out which filesystem a specific directory belongs to and how much space is available.

Filter Out Temporary Filesystems

df -h -x tmpfs -x devtmpfs

Use -x to exclude filesystem types like tmpfs that aren't backed by physical storage.

Why the -h Flag Matters

Without -h, df displays sizes in 1K blocks:

Filesystem     1K-blocks     Used Available Use% Mounted on
/dev/sda1       52428800 29360128  20971520  59% /

With -h, it's much easier to read:

Filesystem      Size  Used Avail Use% Mounted on
/dev/sda1        50G   28G   20G  59% /

Other Useful Options

  • df -hT: Include filesystem type (ext4, xfs, btrfs, etc.)
  • df -hi: Show inode usage instead of disk space
  • df -h --total: Add a total row at the bottom

When to Use df -h

  • Before installing large software: Make sure you have enough space
  • System monitoring: Regular checks prevent unexpected "disk full" errors
  • Troubleshooting: Identify which partition is running out of space
  • Server management: Essential for maintaining healthy systems

Tips

  1. Watch the Use% column: When it exceeds 90%, it's time to clean up or expand storage
  2. Check inodes too: Sometimes you run out of inodes before disk space (df -hi)
  3. Combine with du: Use du -sh * to find which directories are consuming space

Conclusion

df -h is a quick, essential tool for any Linux user or administrator. By making disk space information human-readable, it helps you monitor system health and prevent storage issues before they become problems. Make it part of your regular system maintenance routine!

No comments:

Powered by Blogger.