As a system administrator, IT professional, or cybersecurity professional:
df command in linux helps you manage disk space effectively.
This article covers all aspects of df.
From basic syntax to advanced monitoring techniques.
Perfect for:
- WordPress site managers in India
- Linux sysadmins on production systems
- Anyone needing disk space insights
Table of Contents
- What is the df Command in linux?
- Basic Syntax & Usage df in linux
- Essential Options of df command in linux
- Beginner Examples for df in linux
- Advanced Techniques of df in linux
- df vs du Differences
- Sysadmin Use Cases of df in linux
- Scripting & Automation
- Performance Tips
- Troubleshooting of df in linux
- Best Practices for df command in linux
- Cybersecurity Uses
- 20 Detailed FAQs
What is the df Command in Linux?
The df command, short for “disk free”:
Provides instant filesystem-level disk space usage.
Covers all mounted partitions on Linux/Unix systems.
Unlike du:
durecursively analyzes individual directoriesdfdelivers high-level summaries
Shows for every filesystem:
- Total space
- Used space
- Available space
- Mount percentages
First command sysadmins run.
Investigates "No space left on device" errors.
For Indian hosting providers managing LAMP stacks:
df instantly reveals problematic partitions:
/var/home/tmp
Part of GNU coreutils across:
- Ubuntu
- CentOS
- Debian
- Rocky Linux
Supports:
- Human-readable output
- Inode reporting
- Filesystem type filtering
Critical for 24/7 monitoring.
Prevents production outages.
Provides sub-second disk insights.
Maintains WordPress sites, databases, email servers.
Basic Syntax and Usage
Basic syntax: df [OPTIONS] [FILESYSTEM_LIST]
No arguments shows all mounted filesystems.
Columns displayed:
- Filesystem
- Size
- Used
- Available
- Use%
- Mounted on
Sample output:
/dev/sda1: 50GB total- 45GB used, 5GB available
- 90% utilization at
"/"
Target specific filesystem:
df -h /var shows only /var partition details.
Human-readable: Converts bytes to GB/MB/KB.
Use% column alerts at 80% utilization or more.
df -h takes <0.1 seconds.
Unlike du recursive crawl.
Perfect first-step triage for disk crisis.
Essential df Command in linux Options
Key options transform df into a production monitoring tool.
-h or --human-readable:
- Reports sizes using G/M/TB
- Instead of bytes
-T or --print-type:
- Prints filesystem type
- Example: ext4, xfs, nfs
-i or --inodes:
- Shows inode utilization %
- Critical for
"No space left on device" - When free blocks exist
Customize output options:
--output=columns: Specify output columns.
-x or --exclude: Skip filesystems.
- Example:
--exclude=tmpfsskips ramdisks
--total: Adds grand total line.
-t or --type: Limit by type.
- Example:
-t ext4shows only ext4 partitions
Sysadmin quick overview:
df -hT --total gives complete disk report instantly.
| Option | Purpose | Example |
|---|---|---|
-h |
Human readable | df -h |
-T |
Show filesystem type | df -hT |
-i |
Inode usage | df -i |
df Command Examples for Beginners
Disk capacity methods:
df -h: Human-readable for all filesystems.
watch -n 5 df -h: Refreshes every 5 seconds.
>90% usage alert:
df -h | awk '$5 ~ /9[0-9]/{print}'
WordPress root partition:
df -h /var/www
Capacity check only:
df -h --output=source,target,pcent | grep -v tmpfs
- Excludes ramdisk displays
Multiple servers:
df -h --total | tail -1
- Aggregate usage total
Indian hosting monitoring:
df -h /home /var/www /var/log /tmp
- Customer websites
- WordPress
- Logs
- Tmp files
CLI monitoring = 90% sysadmin needs.
Advanced df Command Techniques
Custom Output:
df --output=source,fstype,size,used,avail,pcent,target --noheader
- Creates aligned column tables
Limit output:
df -t nfs: NFS file systems only
df -x loop: Excludes loop devices
Inode crisis detection:
df -i / | awk '$5 > 90{print}'
Portable monitoring:
df -h --local
- Hard drives only
- Ignores Windows/networked filesystems
Filesystem health check:
df -hT | grep -E "(ext4|xfs)"
- Data partitions only
Alert threshold (85%+):
df -h | awk 'NR>1 && $5+0 > 85{print $0 " ALERT!"}'
Production-level monitoring insights follow.
df vs du: Critical Differences Explained
df = filesystem totals (instant), du = directory totals (slow recursive). df shows 100% used when processes hold deleted files open. du misses these “ghost” files. Solution: lsof | grep deleted + service restart.
| Metric | df | du |
|---|---|---|
| Scope | Filesystem | Directory |
| Speed | Instant | Minutes |
| Use Case | Alerts | Cleanup |
Workflow: df -h ā alert ā du -sh /* ā cleanup.
Real-World Sysadmin Use Cases
Web servers:
df -h /var/www /tmp /var/log
- Check space usage
FIFO databases:
df -h /var/lib/mysql with watch command.
Email servers:
df -h /var/spool or df -h /home.
Backups:
df -h /backup or df -h /mnt/usb.
Indian hosting disk alert:
df -h --output=pcent,target | awk '$1>85{print $2 "CRITICAL: " $1}' | mail -s "Disk Alert" ad***@**st.com
Pre-upgrade check:
df -h --min-cols | grep -v "100%"
Nagios-style check:
df -l | tail -1 | awk '{print $5}' | sed 's/%//'
These cover 95% production monitoring.
df in Scripting and Automation
#!/bin/bash
REPORT="/var/log/df-report-$(date +%Y%m%d).txt"
echo "Disk Space Report: $(date)" > $REPORT
df -hT --output=source,fstype,size,used,avail,pcent,target >> $REPORT
CRITICAL=$(df -h --output=pcent,target | awk 'NR>1 && $1+0>90{print $2}')
if [ ! -z "$CRITICAL" ]; then
echo "CRITICAL: $CRITICAL" | mail -s "URGENT Disk Full" op*@*****ny.com
fi
echo "Top 5 fullest:" >> $REPORT
df -h --output=pcent,target | sort -hr | head -6 >> $REPORT
Cron: */5 * * * * /usr/local/bin/df-monitor.sh
Performance Tips for df Monitoring
df executes instantly regardless of filesystem size. Optimize parsing: df -h --noheader --output=pcent,target | while read pct mount; do [ ${pct%\%} -gt 85 ] && echo "ALERT $mount"; done. Cache results: df -h > /var/run/df.cache; watch -n 30 'tail -10 /var/run/df.cache'.
Zabbix/Nagios: df --output=pcent,$MOUNTPOINT | tail -1. Multi-server: for host in server1 server2; do ssh $host "df -h --total / | tail -1"; done. Avoid df -a (includes empty mounts). Use --local for production servers excluding NFS.
Common Errors and Troubleshooting while using df command in linux
100% used but du shows space: Deleted open files: lsof | grep deleted ā restart service. Inodes full: df -i ā find small file floods. NFS stale: df -t nfs ā umount -f. “No such file”: Use mountpoint paths.
Script fix: df -h --output=source,pcent,target 2>/dev/null | awk 'NR>1 && $2+0>95{print "CRITICAL: " $3 " (" $2 ")"}'. Common after log rotation failures, mysqldump hangs, WordPress upload limits. Always check inodes + blocks.
Best Practices for Disk Monitoring
- Alert at 80%, critical 90%.
- Monitor inodes + blocks.
- Exclude tmpfs/devtmpfs.
- Baseline per filesystem type.
- 5-minute cron intervals.
- Email + Slack + PagerDuty.
- Capacity planning (never <20% free).
WordPress: /var/www, /tmp, /var/log.
Database: /var/lib/mysql.
Enterprise: Integrate Prometheus Node Exporter.
Indian SMBs: Focus /home quotas.
Document thresholds per server role (web/mail/db/backup).
df Command in Cybersecurity
Ransomware fills /tmp: watch -n 10 'df -h /tmp /var/tmp | tail -1'. Crypto-miners target /dev/shm: df -x tmpfs | grep shm. DDoS log floods: df -h /var/log | awk '$5>80'.
#!/bin/bash
for fs in /tmp /var/tmp /dev/shm /var/log; do
PCT=$(df -h --output=pcent $fs | tail -1 | tr -d '% ')
if [ $PCT -gt 85 ]; then
echo "SECURITY ALERT: $fs at ${PCT}%" | mail -s "Potential Attack" so*@*****ny.com
fi
done
20 Detailed FAQs on df Command in linux
- What does “df” stand for? Disk Free. Shows filesystem totals instantly across all mounts.
- Human-readable output?
df -h. Converts bytes to K/M/G/TB + percentages. - df shows 100% but space exists? Deleted-but-open files.
lsof | grep deleted+ restart service. - Check specific partition only?
df -h /varordf -h /dev/sda1. - Show filesystem types?
df -hT. Identifies ext4/xfs/nfs for troubleshooting. - Monitor inode usage?
df -i. Finds “No space left” with free blocks. - Alert on 90%+ usage?
df -h | awk '$5 ~ /[9][0-9]/{print}'. - Exclude tmpfs/ramdisks?
df -x tmpfsordf --local. - Custom columns only?
df --output=source,pcent,target. - Show grand total?
df -h --total. Aggregate across all filesystems. - NFS mounts only?
df -t nfs. Network storage monitoring. - Refresh every 10 seconds?
watch -n 10 df -h. - JSON output for monitoring?
df --output=json(newer versions). - Find fullest filesystem?
df -h --output=pcent | sort -hr | head -2. - Local disks only?
df -lexcludes network mounts. - Script exit code on threshold?
df -h | awk '$5+0>90{exit 2}'. - WordPress monitoring?
df -h /var/www /tmp /var/log. - Database partition check?
df -h /var/lib/mysql /var/lib/pgsql. - Cron monitoring example? 5-minute disk alerts with email.
- Best GUI replacement?
baobabor server monitoring dashboards.
Stay Connected with My Coding Journey
Don’t let scammers stop your professional growth. Join our community for more tech safety tips!
For more tutorials and guides, check out: Basic linux commands
š Visit My Official Website
Linkedln Connect on LinkedIn
For more tutorials and guides, check out: CodingJourney.co.in