0
0
Linux-cliHow-ToBeginner · 3 min read

How to Use df Command in Linux: Syntax and Examples

Use the df command in Linux to display disk space usage of file systems. Running df -h shows human-readable sizes for easier understanding. This command helps monitor available and used disk space quickly.
📐

Syntax

The basic syntax of the df command is:

  • df [options] [file]

Here, options modify the output format, and file is an optional path to check the disk usage of the file system containing that file.

Common options include:

  • -h: Show sizes in human-readable format (e.g., 1K, 234M, 2G).
  • -T: Display the file system type.
  • -a: Include all file systems, even dummy ones.
bash
df [options] [file]
💻

Example

This example shows how to use df -h to display disk usage in a readable format:

bash
df -h
Output
Filesystem Size Used Avail Use% Mounted on /dev/sda1 50G 20G 28G 42% / tmpfs 1.9G 0 1.9G 0% /dev/shm /dev/sdb1 100G 60G 35G 64% /data
⚠️

Common Pitfalls

Some common mistakes when using df include:

  • Not using -h option, which makes sizes hard to read as they are in blocks.
  • Confusing df output with du, which shows directory sizes, not disk usage.
  • Expecting df to show free space on specific files instead of file systems.

Wrong usage example:

df /home/user/file.txt

This shows the file system containing the file, not the file size.

Right usage to check disk space:

df -h
bash
df /home/user/file.txt
df -h
Output
/dev/sda1 50G 20G 28G 42% / Filesystem Size Used Avail Use% Mounted on /dev/sda1 50G 20G 28G 42% /
📊

Quick Reference

OptionDescription
-hShow sizes in human-readable format
-TDisplay file system type
-aInclude all file systems
-iShow inode usage instead of block usage
[file]Show disk usage of the file system containing this file

Key Takeaways

Use df -h to see disk space in easy-to-read sizes.
The df command shows file system usage, not individual file sizes.
Common mistake: forgetting -h makes output hard to understand.
Use options like -T to get more details about file systems.
Check disk space regularly to avoid running out of storage.