Mastering the `df` Command: Your Essential Guide to Linux Disk Space Management
Efficiently managing Linux disk space is crucial for system stability and performance. While many third-party utilities exist, the built-in df command remains an indispensable tool for any system administrator. This powerful utility, short for "disk filesystem," provides a comprehensive overview of available and used disk space across your filesystem. Dive into this guide to unlock df‘s full potential, learn advanced flags, interpret its output effectively, and proactively address potential disk space issues before they impact your operations.
On the internet, you will find plenty of tools for checking disk space usage in Linux. However, Linux has a strong built-in utility called ‘df‘.
The ‘df‘ command stands for “disk filesystem“, it is used to get a full summary of available and used disk space usage of the file system on the Linux system.
Using ‘-h‘ parameter with (df -h) will show the file system disk space statistics in “human-readable” format, which means it gives the details in bytes, megabytes, and gigabytes.
In this guide, we’ll go beyond the basic flags and show you how to actually read df output, combine options for more useful results, and catch disk space problems before they cause downtime.
Understanding the `df` Command Output
When you run df, it reports six columns for each mounted filesystem:
| Column | What It Means |
|---|---|
| Filesystem | The device or filesystem name (e.g., /dev/sda1) |
| 1K-blocks | Total size in 1024-byte blocks |
| Used | Space currently in use |
| Available | Space still available to non-root users |
| Use% | Percentage of space used |
| Mounted on | Where the filesystem is mounted in your directory tree |
Note: The Available column is not simply “Total minus Used.” Linux reserves a portion of each filesystem (typically 5%) for the root user to prevent system crashes when disk space runs low. This is why Used + Available often doesn’t equal the total size.
`df` Command Syntax
If no filesystem is specified, df reports on all currently mounted filesystems.
df [OPTIONS] [FILESYSTEM]
Practical `df` Command Examples for Linux System Administrators
1. Checking Overall Linux Disk Space Usage
The df command displays fundamental information: device name, total blocks, total disk space, used disk space, available disk space, and mount points on a file system. This raw output is useful for scripting where programmatic parsing of block numbers is preferred.
sudo df
For daily **disk management Linux** tasks, you’ll almost always want to add -h for better readability.
2. Human-Readable Output: The Essential `df -h`
The -h (human-readable) flag is arguably the most frequently used option. It automatically converts byte counts into KB, MB, GB, or TB, making the output instantly understandable.
df -h
Sample output:
Filesystem Size Used Avail Use% Mounted on tmpfs 3.2G 2.6M 3.2G 1% /run /dev/sda1 696G 321G 339G 49% / tmpfs 16G 861M 15G 6% /dev/shm tmpfs 5.0M 12K 5.0M 1% /run/lock efivarfs 256K 49K 203K 20% /sys/firmware/efi/efivars tmpfs 16G 0 16G 0% /run/qemu /dev/sda2 286M 6.2M 280M 3% /boot/efi tmpfs 3.2G 156K 3.2G 1% /run/user/1000 /dev/sdb3 274G 2.9G 258G 2% /media/ravi/Personal_Sites /dev/sdb1 229G 211G 6.0G 98% /media/ravi/Personal_Data /dev/sdb2 458G 74G 361G 17% /media/ravi/Linux_VM
Pro Tip: Any time Use% is above 85%, treat it as a warning sign and investigate. At 95%+, you may start seeing application errors, failed writes, and corrupted log files.
3. Displaying All Filesystems, Including Pseudo Filesystems (`df -a`)
The command df -a is used to display information about all mounted filesystems, including pseudo filesystems like tmpfs, sysfs, proc, and devtmpfs, which typically show 0 blocks and are hidden by default. This is particularly useful when debugging container environments, chroot setups, or systemd mount unit issues where a pseudo-filesystem mount isn’t behaving as expected.
df -a
4. Identifying Filesystem Types with `df -Th`
Combining -T (type) and -h (human-readable) provides a much more informative overview. This is especially helpful when managing servers with a mix of ext4, xfs, and btrfs filesystems, as it helps determine which tools to use for resizing or repair.
df -Th
Sample output:
Filesystem Type Size Used Avail Use% Mounted on tmpfs tmpfs 3.2G 2.6M 3.2G 1% /run /dev/sda1 ext4 696G 321G 339G 49% / tmpfs tmpfs 16G 869M 15G 6% /dev/shm tmpfs tmpfs 5.0M 12K 5.0M 1% /run/lock efivarfs efivarfs 256K 49K 203K 20% /sys/firmware/efi/efivars tmpfs tmpfs 16G 0 16G 0% /run/qemu /dev/sda2 vfat 286M 6.2M 280M 3% /boot/efi tmpfs tmpfs 3.2G 160K 3.2G 1% /run/user/1000 /dev/sdb3 ext4 274G 2.9G 258G 2% /media/ravi/Personal_Sites /dev/sdb1 ext4 229G 211G 6.0G 98% /media/ravi/Personal_Data /dev/sdb2 ext4 458G 74G 361G 17% /media/ravi/Linux_VM
5. Monitoring Specific Directories or Partitions
To check the **Linux disk space** usage of a particular directory or partition in a human-readable format, simply append its path to the df command. The -T option, as shown, also displays the filesystem type.
df -hT /home
You can also check multiple directories at once:
df -h / /home /var
6. Viewing Disk Space in Kilobytes (`df -k`)
To display all mounted filesystem information and usage in 1024-byte blocks, use the -k option (e.g., --block-size=1K), which provides information about each filesystem on your system, presenting sizes in kilobytes (KB).
sudo df -k
7. Viewing Disk Space in Megabytes (`df -m`)
To display information on all file system usage in MB (Megabytes), use the option -m, which presents sizes in megabytes (MB).
sudo df -m
8. Forcing Gigabyte Units with `df -BG`
The -B flag allows you to specify an explicit block size. -BG forces gigabyte units, -BM forces megabytes, and -BK forces kilobytes. This provides predictable, fixed-unit output for scripts and reports, unlike the auto-scaling behavior of -h.
sudo df -BG
Sample output:
Filesystem 1G-blocks Used Available Use% Mounted on tmpfs 4G 1G 4G 1% /run /dev/sda1 696G 321G 339G 49% / tmpfs 16G 1G 15G 6% /dev/shm tmpfs 1G 1G 1G 1% /run/lock efivarfs 1G 1G 1G 20% /sys/firmware/efi/efivars tmpfs 16G 0G 16G 0% /run/qemu /dev/sda2 1G 1G 1G 3% /boot/efi tmpfs 4G 1G 4G 1% /run/user/1000 /dev/sdb3 274G 3G 258G 2% /media/ravi/Personal_Sites /dev/sdb1 229G 211G 6G 98% /media/ravi/Personal_Data /dev/sdb2 458G 74G 361G 17% /media/ravi/Linux_VM
Note: df -h and df -BG are not the same. -h auto-selects the most readable unit per filesystem (so a 500MB partition shows in MB, not GB). -BG forces GB across the board, which means small filesystems might show as 0G.
9. Diagnosing Inode Usage in Linux (`df -ih`)
Inodes are what Linux uses to track files and directories – not file contents, but the metadata (permissions, ownership, timestamps, pointers to data blocks). A filesystem can run out of inodes while still having plenty of disk space, leading to “No space left on device” errors even if df -h shows free space available. Checking **inode usage Linux** is vital for comprehensive **Linux filesystem monitoring**.
df -ih
Sample output:
Filesystem Inodes IUsed IFree IUse% Mounted on tmpfs 4.0M 1.3K 4.0M 1% /run /dev/sda1 45M 1.6M 43M 4% / tmpfs 4.0M 2.2K 4.0M 1% /dev/shm tmpfs 4.0M 8 4.0M 1% /run/lock efivarfs 0 0 0 - /sys/firmware/efi/efivars tmpfs 4.0M 1 4.0M 1% /run/qemu /dev/sda2 0 0 0 - /boot/efi tmpfs 801K 152 801K 1% /run/user/1000 /dev/sdb3 18M 9.5K 18M 1% /media/ravi/Personal_Sites /dev/sdb1 15M 21K 15M 1% /media/ravi/Personal_Data /dev/sdb2 30M 2.2K 30M 1% /media/ravi/Linux_VM
Warning: If IUse% is above 90%, you have an inode exhaustion problem. This commonly occurs on mail servers, web servers with many small cache files, or systems where a runaway process has created thousands of temporary files.
10. Filtering `df` Output to Show Only a Specific Filesystem Type
This command shows disk usage only for ext4 filesystems, which is useful on systems with a mix of filesystem types when you want to focus on just one kind.
df -t ext4 -h
Sample Output:
Filesystem Size Used Avail Use% Mounted on /dev/sda1 696G 321G 339G 49% / /dev/sdb3 274G 2.9G 258G 2% /media/ravi/Personal_Sites /dev/sdb1 229G 211G 6.0G 98% /media/ravi/Personal_Data /dev/sdb2 458G 74G 361G 17% /media/ravi/Linux_VM
Similarly, to check only xfs filesystems:
df -t xfs -h
11. Excluding Filesystem Types from `df` Output
The -x option excludes the specified filesystem type from the output. This is handy for cleaning up df -h output on systems where tmpfs mounts (for /dev/shm, /run, etc.) clutter the display and aren’t relevant to what you’re checking for **Linux disk space** issues.
df -x tmpfs -h
Sample Output:
Filesystem Size Used Avail Use% Mounted on /dev/sda1 696G 321G 339G 49% / efivarfs 256K 49K 203K 20% /sys/firmware/efi/efivars /dev/sda2 286M 6.2M 280M 3% /boot/efi /dev/sdb3 274G 2.9G 258G 2% /media/ravi/Personal_Sites /dev/sdb1 229G 211G 6.0G 98% /media/ravi/Personal_Data /dev/sdb2 458G 74G 361G 17% /media/ravi/Linux_VM
12. Customizing `df` Output Columns
The --output option lets you specify exactly which columns appear and in what order. This is particularly useful in scripts and monitoring tools where you need a specific column layout. Available fields include: source, fstype, itotal, iused, iavail, ipcent, size, used, avail, pcent, file, and target.
df -h --output=source,fstype,size,used,avail,pcent,target
Sample Output:
Filesystem Type Size Used Avail Use% Mounted on tmpfs tmpfs 3.2G 2.9M 3.2G 1% /run /dev/sda1 ext4 696G 321G 339G 49% / tmpfs tmpfs 16G 859M 15G 6% /dev/shm tmpfs tmpfs 5.0M 12K 5.0M 1% /run/lock efivarfs efivarfs 256K 49K 203K 20% /sys/firmware/efi/efivars tmpfs tmpfs 16G 0 16G 0% /run/qemu /dev/sda2 vfat 286M 6.2M 280M 3% /boot/efi tmpfs tmpfs 3.2G 164K 3.2G 1% /run/user/1000 /dev/sdb3 ext4 274G 2.9G 258G 2% /media/ravi/Personal_Sites /dev/sdb1 ext4 229G 211G 6.0G 98% /media/ravi/Personal_Data /dev/sdb2 ext4 458G 74G 361G 17% /media/ravi/Linux_VM
13. Real-time Linux Disk Space Monitoring with `watch` and `df`
The watch command re-runs df -h every 5 seconds and highlights changes. Use this when you’re running a large file copy, database dump, or log-generating operation and want to see disk space change in real time without manually re-running the command. This is an excellent technique for proactive **Linux filesystem monitoring**.
watch -n 5 df -h
Sample Output:
Every 5.0s: df -h tecmint: Tue Mar 31 12:04:11 2026 Filesystem Size Used Avail Use% Mounted on tmpfs 3.2G 2.9M 3.2G 1% /run /dev/sda1 696G 321G 339G 49% / tmpfs 16G 872M 15G 6% /dev/shm tmpfs 5.0M 12K 5.0M 1% /run/lock efivarfs 256K 49K 203K 20% /sys/firmware/efi/efivars tmpfs 16G 0 16G 0% /run/qemu /dev/sda2 286M 6.2M 280M 3% /boot/efi tmpfs 3.2G 164K 3.2G 1% /run/user/1000 /dev/sdb3 274G 2.9G 258G 2% /media/ravi/Personal_Sites /dev/sdb1 229G 211G 6.0G 98% /media/ravi/Personal_Data /dev/sdb2 458G 74G 361G 17% /media/ravi/Linux_VM
14. Sorting `df` Output by Usage Percentage for Quick Alerts
This pipes df -h output through sort, ordering results by the Use% column (field 5) in reverse numeric order – so the most full filesystems appear at the top. This is the quickest way to spot which partition needs attention on a server with many mounts, crucial for effective **Linux disk space** management.
df -h | sort -k5 -rn
Sample Output:
/dev/sdb1 229G 211G 6.0G 98% /media/ravi/Personal_Data /dev/sda1 696G 321G 339G 49% / efivarfs 256K 49K 203K 20% /sys/firmware/efi/efivars /dev/sdb2 458G 74G 361G 17% /media/ravi/Linux_VM tmpfs 16G 862M 15G 6% /dev/shm /dev/sda2 286M 6.2M 280M 3% /boot/efi /dev/sdb3 274G 2.9G 258G 2% /media/ravi/Personal_Sites tmpfs 5.0M 12K 5.0M 1% /run/lock tmpfs 3.2G 2.9M 3.2G 1% /run tmpfs 3.2G 164K 3.2G 1% /run/user/1000 tmpfs 16G 0 16G 0% /run/qemu Filesystem Size Used Avail Use% Mounted on
Pro Tip: Add this as an alias in your ~/.bashrc for quick daily checks:
alias dfs="df -h | sort -k5 -rn"
15. Exploring `df` Command Options (`df –help`)
For a brief overview of all available options and their descriptions, use the --help flag. For the full, comprehensive manual page, always refer to man df.
df --help
Sample Output:
Usage: df [OPTION]... [FILE]...
Show information about the file system on which each FILE resides,
or all file systems by default.
Mandatory arguments to long options are mandatory for short options too.
-a, --all include pseudo, duplicate, inaccessible file systems
-B, --block-size=SIZE scale sizes by SIZE before printing them; e.g.,
'-BM' prints sizes in units of 1,048,576 bytes;
see SIZE format below
-h, --human-readable print sizes in powers of 1024 (e.g., 1023M)
-H, --si print sizes in powers of 1000 (e.g., 1.1G)
-i, --inodes list inode information instead of block usage
-k like --block-size=1K
-l, --local limit listing to local file systems
...Advanced `df` Scenarios: Troubleshooting Common Linux Disk Issues
Here are practical scenarios that actually happen in production environments, and how `df` can help in **Linux disk space management**.
Scenario 1: Disk Full but You Can’t Find What’s Filling It – The Open File Dilemma
df -h shows /var at 99%, but du -sh /var/* shows only 10GB used. This classic mismatch usually means a deleted file is still held open by a running process — the space won’t be freed until that process closes or restarts. To identify the culprits:
# Find processes holding deleted files open lsof +L1 | grep /var
Restart the relevant service, and the space will free up immediately.
Scenario 2: “No Space Left on Device” Error Despite Free Disk Space
If an application is throwing “No space left on device” errors, but df -h shows plenty of free space, you likely have an **inode exhaustion** problem. Check inodes first:
df -ih /var
If IUse% is at or near 100%, you’ve hit inode exhaustion. Common culprits include mail queues with millions of tiny emails, PHP session files, or container overlay layers generating numerous small temporary files.
Scenario 3: Automating Disk Space Alerts with `df` and Cron
This script checks all mounted filesystems and sends an alert email when any partition crosses 85% usage. A cornerstone of proactive **Linux filesystem monitoring**.
#!/bin/bash
THRESHOLD=85
df -h --output=pcent,target | tail -n +2 | while read PCT MNT; do
NUM=${PCT%%%}
if [ "$NUM" -ge "$THRESHOLD" ]; then
echo "WARNING: $MNT is at $PCT" | mail -s "Disk Alert: $MNT" your_email@example.com
fi
done`df` vs. `du`: Understanding the Key Differences for Effective Disk Management
A common point of confusion for new and even experienced Linux users is when to use df versus du. Both are vital for **Linux disk management**, but serve different purposes:
| Aspect | df | du |
|---|---|---|
| What it reports | Free/used space on a mounted filesystem | Disk space consumed by specific files and directories |
| Speed | Instant — reads filesystem metadata | Slower — walks the directory tree |
| Use case | “Is this partition full?” | “What is filling up this partition?” |
Use df first to identify which partition is the problem, then use the du command to drill down into what is causing it.
Quick Reference: Essential `df` Commands for Linux System Administration
| Command | Description |
|---|---|
df -h | Human-readable overview of all filesystems |
df -Th | Include filesystem type |
df -ih | Check inode usage |
df -h /var | Check a specific partition |
df -t ext4 -h | Show only ext4 filesystems |
df -x tmpfs -h | Exclude tmpfs from output |
df -h | sort -k5 -rn | Sort by usage percentage (busiest first) |
watch -n 5 df -h | Live monitoring every 5 seconds |
df -BG | Force gigabyte units |
df -h --output=source,size,used,avail,pcent,target | Display custom output columns |
Conclusion
The df command is a cornerstone of **Linux disk space** analysis, offering a straightforward yet powerful way to assess filesystem health. While its basic flags are easy to grasp, mastering its advanced options, understanding edge cases like **inode usage Linux**, and automating alerts are what truly elevate reactive troubleshooting to proactive **disk management Linux**. By integrating these techniques, you can ensure your Linux systems remain stable and performant.
If your immediate problem is a full disk and you need to find what’s eating space, pair df -h with du -sh /* | sort -rh | head -20 to quickly identify the largest directories.
For related disk management tools, see:
You might also like:
FAQ
Question 1: Why do `df -h` and `du -sh /*` often show different disk usage?
Answer 1: This is a common point of confusion. df -h reports disk space usage from the perspective of the filesystem, taking into account blocks allocated to files (even deleted ones still held open by processes) and reserved space for root. du -sh /*, on the other hand, calculates disk usage by traversing the directory tree and summing up the sizes of individual files. The primary reasons for discrepancies are:
- Deleted but Open Files: Files that have been deleted but are still held open by a running process (e.g., a log file being written to) will free up their space only when the process releases them.
dfcounts this space as “used,” whileduwon’t see the deleted entry. - Reserved Blocks: Filesystems typically reserve a small percentage (e.g., 5%) of blocks for the root user to prevent the system from grinding to a halt when the disk is completely full.
dfaccounts for this reserved space, whereasduonly reports actual file sizes. - Hard Links:
ducounts hard-linked files multiple times if they appear in different directories traversed, whiledfcounts the space only once.
The general rule is: use df to understand how full a *partition* is, and du to find *what* is consuming space within a directory structure.
Question 2: What does “inode exhaustion” mean, and how can I fix it?
Answer 2: Inode exhaustion occurs when a filesystem runs out of inodes, even if there’s plenty of free disk space remaining. Inodes are data structures that store metadata about files and directories (like permissions, ownership, timestamps, and physical location on disk), but *not* the file content itself. Each file or directory on a Linux system requires one inode. If you create millions of tiny files (e.g., mail server queues, web session files, temporary build artifacts), you can deplete the available inodes before filling the disk’s storage capacity, leading to “No space left on device” errors.
To fix it:
- Identify Culprits: Use
df -ihto confirm inode exhaustion. Then, usefor i in /*; do echo $i; find $i | wc -l; done(or similar recursive commands) to find directories containing an unusually large number of files. - Delete Small, Unnecessary Files: Focus on cleaning up temporary files, old logs, cache files, or mail queues. For example,
find /path/to/directory -type f -name "*.tmp" -deletecan help. - Increase Inode Count (Advanced): For new filesystems, you can specify a higher inode-to-block ratio during creation (e.g., with
mke2fs -i). However, you cannot easily change the inode count on an *existing* mounted filesystem without reformatting it (which destroys all data). This is why careful planning of inode density is important for filesystems expected to store many small files.
Question 3: Is there a GUI tool for Linux filesystem monitoring that uses `df` data?
Answer 3: While df is a powerful command-line tool, several GUI applications provide a visual representation of **Linux disk space** usage, often leveraging data similar to what df provides. A popular and highly effective tool is Baobab Disk Usage Analyzer (often found as “Disk Usage Analyzer” in your applications menu). It scans your filesystem and presents a graphical treemap or sunburst chart, making it easy to spot large directories and files.
Another excellent option, particularly for visual CLI users, is ncdu (NCurses Disk Usage). While technically a terminal-based tool, its interactive interface with navigation and sorting capabilities makes it feel very much like a GUI, offering quick insights into what’s consuming disk space in a hierarchical view. It’s often available in most Linux distribution repositories.

