Linux commands let you check disk space instantly, which is essential for optimizing storage—whether you’re monitoring system health, cleaning up files, or troubleshooting slow performance. Unlike graphical tools like GNOME Disks or Nautilus, these commands work in any terminal, run in seconds, and provide detailed output about each partition. No additional software is required; just run a few quick lines, and you’ll see partitions, usage percentages, and available space at a glance. This guide covers the most practical methods, including hidden flags, common mistakes, and how to interpret results.
What You'll Need
- Access to a Linux terminal (available by default on most Linux distributions).
- Basic familiarity with terminal commands—you’ll need to run lines like `df`, `lsblk`, and `du`.
- A storage device (disk or partition) to analyze—typically / (root), /home, or external drives.
Step-by-Step
-
Use `df` to see all mounted partitions and their free space
Open the terminal (press Ctrl+Alt+T or search "Terminal").
Run:
df -hExplanation: - The-hflag converts sizes to human-readable formats (e.g., GB, MB). - Output lists each mounted filesystem (e.g., /, /home) alongside its used/free space. Example output:Filesystem Size Used Avail Use% Mounted on /dev/sda1 50G 30G 20G 60% / /dev/sda2 200G 50G 150G 25% /homeKey columns:Size: Total disk space.Used: Amount consumed by files.Avail: Free space.Use%: Percentage used (critical for triggering cleanup).
-
Check a single partition (e.g., /home) with `df -x tmpfs`
Run:
df --output=source,avail -x tmpfsWhy? - Filters out tmpfs (RAM-based storage), giving cleaner output for non-temporary mounts. - Example:df --output=source,avail --no-headers -x tmpfslists only the partition path and free space. -
Scan for large files (>1GB) with `du`
Navigate to a directory (e.g., home folder) and run:
sudo du -ahx /home | grep '[0-9]\{1,3\}G' | sort -hrBreakdown:sudo: Requires admin rights to scan system directories.-ahx: Shows all files (-a), sizes (-h), and hard links (-x).grep '[0-9]\{1,3\}G': Filters for files >1GB.sort -hr: Sorts by size (descending).
du -sh */ | sort -nlists top directories by size. -
Check filesystem health with `fsck` (if needed)
Run:
sudo fsck -f /dev/sdXWhen to use: Only if you suspect disk errors (e.g., after crashes). ReplacesdXwith your partition (e.g.,sda1). Warning: This scans but doesn’t fix errors (usefsckwith no arguments for a full check).
Common Mistakes
-
Forgetting `-h` in `df`:
The command shows raw bytes (e.g., 123456784) instead of readable units (e.g., 117GB). Always add
-hfor clarity. -
Using root (sudo) without permission:
Some commands like
durequire admin rights—always prepend withsudoif needed. -
Ignoring tmpfs in `df`:
Temporary RAM filesystems (e.g., /run, /tmp) report 0GB free but aren’t storage. Use
-x tmpfsto exclude them. -
Misinterpreting free space:
Availis the technically free space, but real usable space may be lower due to filesystem overhead (e.g., 10% reserved by ext4).
Tips
-
Monitor disk usage over time:
Store `df -h` results in a log file by redirecting output:
df -h > disk_usage.log -
Filter by mount point:
For example, check only /home’s free space:
df /home | awk '{print $4}' -
Use `ncdu` for interactive analysis:
Install it with
sudo apt install ncdu(Debian/Ubuntu) for a GUI-like tool with filtering/sorting. -
Check ext4 reserved space:
Run
tune2fs -l /dev/sdX | grep "Reserved block count"to see how much is set aside for root (e.g., 10%). -
Exclude non-critical mounts:
For example, skip network drives:
df --output=source --no-headers -x nfs,tmpfs
Troubleshooting
-
Command returns "No such file or directory":
- The partition isn’t mounted. Check with
lsblkto verify the device exists. - Run
mount | grep /dev/sdXto confirm it’s active. - Mount it manually if needed:
sudo mount /dev/sdX /mnt.
- The partition isn’t mounted. Check with
-
`df` shows 0GB free even when the drive isn’t full:
- Check for hidden files (e.g., systemd journals, kernel logs):
sudo journalctl --disk-usage - Search for large files in your home:
sudo find ~ -type f -size +1G -exec ls -lh {} \;
- Check for hidden files (e.g., systemd journals, kernel logs):
-
Results differ between `df` and `du`:
This is normal.
dfshows available space on the filesystem, whiledumeasures actual file sizes (including subdirectories). -
Slow performance after running `du`:
Large scans (e.g.,
du -ahx /) can take minutes. Restart the system if needed.
Frequently Asked Questions
How do I check free space on an external drive?
Run df -h /dev/sdX (replace sdX with your drive, e.g., sdb1). If the drive isn’t mounted, mount it first:
sudo mount /dev/sdX /mnt.
Why is my free space reported as 0GB even when I have files?
This happens if the filesystem is corrupted or if hidden system files (e.g., swap partitions, tmpfs) are misreporting space. Run sudo fsck /dev/sdX (replace sdX) to scan for errors.
Can I check free space for a specific filesystem type (e.g., NTFS)?
Linux cannot natively read NTFS/exFAT without tools like ntfs-3g or exfat-fuse. Install ntfs-3g first:
sudo apt install ntfs-3g then use df /dev/sda1 (assuming NTFS drive).
How often should I run these checks?
Run df -h weekly to monitor storage trends. For large files, use du monthly to identify bloated directories.
What does "Use%" mean in `df`?
This shows the percentage of space used. Values above 80% may indicate imminent performance issues; aim to keep it under 70% for critical systems.
Can I automate these checks?
Yes! Set up a cron job to run daily:
0 3 * * * df -h >> ~/disk_usage.log
This logs results to a file for review.