Bash Disk Space (df)
Check disk space usage and availability
💾 What is the df Command?
The df command displays disk space usage for file systems. It shows how much space is used and available on your drives, helping you monitor storage capacity and prevent running out of disk space on your computer.
# Check disk space
df -h
DF Features
Space Usage
View used and available space
df
Human Readable
Display in GB/MB format
df -h
Specific Drive
Check particular file system
df -h /home
File System Type
Show file system types
df -T
🔹 Basic Usage
The tail command is a core utility for viewing the end portion of files, particularly useful for logs and large text files. Its default behavior, invoked simply as tail filename, is to output the last 10 lines to the terminal. This provides a quick, resource-efficient way to inspect the most recent entries without loading the entire file. It is indispensable for system administrators checking the latest system log entries (/var/log/syslog), developers verifying the end of application output, or anyone needing a snapshot of recent data. The command reads input from files or standard input, making it highly versatile in pipelines.
# View disk space (in blocks)
df
Output:
Filesystem 1K-blocks Used Available Use% Mounted on /dev/sda1 102400000 51200000 46080000 53% / /dev/sda2 204800000 102400000 92160000 53% /home
🔹 Human Readable Format
Using the -h flag with the df command converts disk space figures into human-readable units like gigabytes (GB), megabytes (MB), or kilobytes (KB). This replaces the default 1K blocks with intelligible sizes, making it effortless to gauge storage consumption at a glance. For example, df -h clearly shows if a drive is nearly full. This option is critical for system administrators and users who need to quickly identify which partitions are running low on space, plan for expansions, or initiate cleanup procedures without manual calculation.
# View in GB/MB format
df -h
Output:
Filesystem Size Used Avail Use% Mounted on /dev/sda1 100G 50G 45G 53% / /dev/sda2 200G 100G 90G 53% /home tmpfs 7.8G 1.2M 7.8G 1% /tmp
🔹 Understanding DF Output
Each column in the df command's output provides specific, crucial information about your file systems' health and capacity. The 'Filesystem' column lists the device or partition name. 'Size' shows total capacity, 'Used' indicates consumed space, 'Avail' displays free space, 'Use%' gives the utilization percentage for quick assessment, and 'Mounted on' specifies the directory where the file system is attached. Interpreting these columns correctly allows you to monitor disk usage trends, proactively plan for storage upgrades, and pinpoint exactly which drives or partitions require immediate attention.
Column Meanings:
- Filesystem - Device name or partition identifier
- Size - Total capacity of the file system
- Used - Amount of space currently occupied
- Avail - Space available for new files
- Use% - Percentage of space used
- Mounted on - Directory where file system is accessible
🔹 Show File System Type
The -T option with df adds an extra column that reveals the type of each file system, such as ext4, xfs, ntfs, or tmpfs. This information is vital for understanding your storage architecture, ensuring compatibility for operations like mounting or data transfer, and troubleshooting performance issues. Knowing whether a drive uses a journaling file system like ext4 or a temporary one like tmpfs helps in making informed administration decisions. Use df -T to get a complete picture of not just how much space you have, but also how it is structured.
# Show file system types
df -hT
Output:
Filesystem Type Size Used Avail Use% Mounted on /dev/sda1 ext4 100G 50G 45G 53% / /dev/sda2 ext4 200G 100G 90G 53% /home tmpfs tmpfs 7.8G 1.2M 7.8G 1% /tmp
🔹 Check Specific File System
You can target the df command to report on a specific directory or mount point by providing its path as an argument. For instance, df /home or df /dev/sda1 will display usage information only for that particular file system. This focus is incredibly helpful when monitoring a specific drive, partition, or network share without being overwhelmed by data from all mounted systems. It streamlines the output, allowing for quick, targeted analysis and is perfect for scripts that need to check the space on a particular backup volume or application storage.
# Check specific directory
df -h /home
# Check root partition
df -h /
# Check multiple locations
df -h / /home /tmp
Output:
Filesystem Size Used Avail Use% Mounted on /dev/sda2 200G 100G 90G 53% /home
🔹 Show Inodes Information
Using the -i option with df switches the display from block usage to inode usage, showing the consumption of these critical file system metadata structures. Inodes store information about files (ownership, permissions, timestamps), and each file consumes one. A file system can run out of inodes even when there is free disk space, preventing the creation of new files. Running df -i helps diagnose this specific issue, which often occurs in systems with a vast number of small files. Monitoring inodes is a key part of comprehensive storage management.
# Show inode usage
df -i
# Human readable with inodes
df -ih
Output:
Filesystem Inodes IUsed IFree IUse% Mounted on /dev/sda1 6553600 234567 6319033 4% / /dev/sda2 13107200 456789 12650411 4% /home
🔹 Exclude File System Types
The -x or --exclude-type option allows you to filter out specific file system types from the df output, resulting in a cleaner and more relevant report. For example, df -x tmpfs -x devtmpfs will hide temporary and pseudo file systems, focusing the output on physical disks and permanent storage. This is particularly useful for automation scripts and daily monitoring where temporary file systems like tmpfs or proc are not relevant to your available storage analysis, reducing noise and highlighting important data.
# Exclude tmpfs file systems
df -h -x tmpfs
# Exclude multiple types
df -h -x tmpfs -x devtmpfs
# Show only specific type
df -h -t ext4
Output:
Filesystem Size Used Avail Use% Mounted on /dev/sda1 100G 50G 45G 53% / /dev/sda2 200G 100G 90G 53% /home
🔹 Common DF Options
The df command offers a versatile set of options that can be combined to tailor output precisely to your monitoring or troubleshooting needs. Key flags include -h for human-readable sizes, -T for file system types, -i for inode data, and -x for exclusion. Combining these, such as in df -hT, creates powerful one-liners for comprehensive disk analysis. Mastering these options enables system administrators to quickly generate reports, script automated alerts for low disk space, and maintain optimal storage health across servers and workstations.
Useful Options:
- -h - Human readable format (GB, MB, KB)
- -T - Show file system type
- -i - Display inode information
- -t type - Show only specific file system type
- -x type - Exclude specific file system type
- -a - Include pseudo file systems
- --total - Add a total row at the end
- -l - Show only local file systems
# Show total at the end
df -h --total
# Only local file systems
df -hl
# All file systems including pseudo
df -ha
🔹 Practical Examples
Everyday uses of head include validating data files, monitoring log heads, and creating data samples. A data scientist might run head -1000 large_dataset.csv > sample.csv to create a manageable sample for testing scripts. A developer might use head -20 application.log to check recent activity after a deployment. These scenarios highlight head's role as a gatekeeper, providing a safe, controlled way to interact with the beginning of files and streams, which is often where the most current or defining information resides.
# Quick check of main drives
df -h | grep -E '^/dev/'
# Check if drive is over 80% full
df -h | awk '$5 > 80 {print $0}'
# Monitor specific partition
watch -n 5 df -h /home
# Save disk usage report
df -h > disk_report_$(date +%Y%m%d).txt
🔹 Alternative: du Command
While df reports on file system-level usage, the du (disk usage) command drills down to show space consumption by individual directories and files within a file system. This makes du the perfect tool for identifying what specific content is consuming space. When df indicates a partition is full, du helps you find the largest directories to clean up. For example, running du -sh /home/* | sort -rh quickly reveals which user folders are the biggest, enabling targeted cleanup actions to reclaim valuable storage efficiently.
# Check directory size
du -sh /home/user
# Find largest directories
du -h /home | sort -hr | head -n 10
# Check current directory
du -sh *
DF vs DU:
- df - Shows file system level space (drives/partitions)
- du - Shows directory level space (folders/files)
- Use df to check overall drive space
- Use du to find what's using space