The most efficient way to check disk space usage in Linux is by running simple built-in commands like `df`, `du`, or `lsblk`—no external tools or graphical interfaces required. These commands reveal partitions, mounted filesystems, and free space at a glance, helping you identify where storage is full or low. No special setup is needed; just open a terminal and run these commands directly. They work across most Linux distributions (Ubuntu, Fedora, Arch, etc.) and provide immediate feedback for managing disk space.
What You'll Need
- Access to a Linux terminal (most desktop environments have it; check "Applications > Accessories > Terminal" or use keyboard shortcuts like
Ctrl+Alt+Ton Xfce/GNOME). - Basic familiarity with command-line navigation (though the commands themselves are user-friendly).
- Optional: A second terminal or SSH access if you need to check space on a remote server.
Step-by-Step
-
Basic Disk Usage Summary with
dfRun this command to see all mounted filesystems and their free space:df -hBreakdown of flags:**
-h: Human-readable (shows sizes in KB, MB, GB).- Output shows
/dev/sda1(partition),ext4(filesystem type),12G(total),9.8G(used),2.2G(free), and100%(usage percentage).
Example output:
Filesystem Size Used Avail Use% Mounted on /dev/sda1 12G 9.8G 2.2G 81% / tmpfs 3.9G 0 3.9G 0% /dev/shmIf
/(root) is at 100%, you likely need to clean up logs, cached files, or swap space. Check for large directories later withdu. -
Check Disk Usage per Directory with
duUse this to scan large directories for hidden storage bloat:du -sh /path/to/directoryFlags explained:**
-s: Show summary (total size of the directory).-h: Human-readable format.
Examples:**
- Check the
/homedirectory:du -sh /home→ Outputs "12G" if it’s full. - Scan for large files in a specific folder:
du -h --max-depth=1 /var/log | sort -rh(lists largest log files).
Pro tip:** Run
du -axh /to see every major directory’s usage (slower but thorough). -
List Disks and Partitions with
lsblkIdentify your physical disks and partitions (useful for checking external drives or errors):lsblk -fExample output:**
NAME FSTYPE SIZE MOUNTPOINT sda ntfs 500G /media/data sda1 ext4 12G / sdb vfat 512M /boot/efiCompare this to
dfto see which partitions are mounted and their usage. Ifsdashows unallocated space butdfdoesn’t list it, the filesystem might be corrupted (see troubleshooting). -
Check Specific Files or Directories
Use
lsorstatfor deeper inspection:- List files in a directory:
ls -lh /path/to/files(shows sizes in human-readable format). - Get file details (size, permissions):
stat file.txt→ Shows "Size: 1M" for example.
- List files in a directory:
-
Identify Large Files with
findFind files exceeding a size threshold (e.g., 100MB):find /home -type f -size +100M -exec ls -lh {} \;Breakdown:**
-type f: Only files (not directories).-size +100M: Files larger than 100MB.-exec ls -lh {} \;: Lists each file’s details.
Common Mistakes
-
Ignoring the
-hflag indfordu.Without
-h, you’ll see numbers like3221225472(bytes), making it hard to interpret. Always use it for readability. -
Using
dffor local directories.dfonly shows mounted filesystems, not directories on the same filesystem. For local paths, useduinstead. -
Not sorting large directories with
du. Rundu -ahx /path | sort -rhto list directories from largest to smallest. Without sorting, you might miss the biggest culprits. -
Assuming
sda1is the root partition. Partitions can be labeled differently (e.g.,/dev/nvme0n1p2orsdb1for external drives). Checklsblkto confirm.
Tips
-
Automate disk checks with cron.
Add this to your
crontab -eto rundf -hdaily at 2 AM:0 2 * * * df -hLog results to a file for monitoring:
0 2 * * * df -h >> /var/log/disk_usage.log -
Use
ncdufor an interactive tool. Install it with:sudo apt install ncdu(Debian/Ubuntu) orsudo pacman -S ncdu(Arch).It lets you browse directories like a file explorer but with disk usage stats. Run with
ncdu /to scan the root directory. -
Check swap space.
Swap can appear full (
dfshows "Swap:"), but it’s not a real disk. Free space with:free -h→ Look forSwap:under "Mem:" (if swap is active). -
Clear temporary files early.
Remove caches with:
sudo apt clean(Debian) orsudo dnf clean all(Fedora).For manual cleanup, run:
rm -rf /tmp/* /var/tmp/*(safe for most systems, but avoid on shared hosts). -
Use
du --max-depth=1for a quick scan. Run this once to see top-level directory sizes:du --max-depth=1 / | sort -rhThis replaces
du -hfor an overview.
Troubleshooting
If commands don’t display expected output (e.g., no space shows up in df), follow these steps in order:
- Restart the system. A sudden drop in disk space may be due to a kernel or filesystem error. Log off and reboot.
-
Check for corrupted filesystems.
Run
sudo fsck(for root) orsudo fsck /dev/sdX1(replaceXwith your partition, e.g.,sda1):sudo fsck -f /dev/sda1Warning:** This may require ejecting physical drives if the filesystem is corrupted. Never run
fsckon a mounted partition. -
Verify disk partitions with
fdisk. Iflsblkshows unallocated space butdfdoesn’t list it, the partition table might be misconfigured:sudo fdisk -lLook for entries like
[empty)under "Size." If you find them, your system may not recognize the disk properly. -
Check for disk errors with
smartctl. Install it with:sudo apt install smartmontoolsTest disk health:
sudo smartctl -a /dev/sdaLook for warnings like
Reallocated_Sector_Ct(indicating bad sectors). If the disk is failing, back up critical data immediately. -
Reinstall the filesystem (last resort).
If you suspect a filesystem corruption that
fsckcan’t repair, you may need to reinstall it:- For
ext4(most common):sudo mkfs.ext4 /dev/sda1(replacesda1with your partition).Warning:** This will erase all data on the partition. Backup first!
- For
NTFS(Windows drives): Use tools likentfsfix(Linux) or a Windows tool likechkdsk.
- For
Frequently Asked Questions
Why does df show 0% used space when I know the drive is full?
The filesystem might be full, but df could be showing 0% if it’s not mounted or if you’re checking the wrong partition. Use lsblk to confirm the correct partition is mounted (e.g., /dev/sda1 for root). Example: If your /home partition is full but df shows 0%, the mount point might be misconfigured.
How do I check disk usage on a remote Linux server via SSH?
Use the same commands with SSH:
df -h (run on the server) or du -sh /var/log (scan a remote directory).
ssh user@server "df -h" will execute the command remotely. For large directories, use:
ssh user@server "du -ahx /path | sort -rh".
What if my disk is showing 100% usage but I haven’t added any new files?
Common causes:
- Temporary files: Run
du -sh /tmp /var/tmpto clear old logs withrm -rf /tmp/*(for local systems). - Swap space: Check
free -h—swap can fill up unexpectedly (e.g., from heavy system processes or background services). - Thumbnails or cache: Clear them with:
rm -rf ~/.cache/thumbnails/ ~/.thumbnails/ ~/.local/share/thumbnail-cache/(Linux-specific). - Journaling files: Run
sudo journalctl --vacuum-size=100Mto purge old logs.
How do I see which files are taking up the most space in a directory?
Use a multi-step approach:
- First, get a high-level overview:
du -ahx /path/to/directory | sort -rh | head -n 20(shows top 20 largest files). - For deeper inspection, use
find:find /path/to/directory -type f -exec du -h {} + | sort -rh(lists all files with their sizes).
For ncdu, navigate with arrow keys and press d to delete files (interactive mode).
Why does df show a partition with 0% free space, but I can still create new files?
This is normal if the partition is full but not yet at 100% usage (Linux reserves some space for future writes). To confirm, check the filesystem type:
df --output=fstype,use% /dev/sda1
- If it’s
ext4, the partition may be full but not yet at 100% (usedf -ito check inodes). - If it’s a swap partition,
dfwon’t show it (swap is managed separately).
For true full partitions, you must free up space (e.g., by deleting files or expanding the partition).
How can I check disk space usage in real-time while a file is being written?
Use iostat (from sysstat package) to monitor I/O:
- Install
sysstatwith:sudo apt install sysstat(Debian) orsudo dnf install sysstat(Fedora). - Run in real-time:
iostat -x 1(shows disk I/O every second).
Look for high r/s (reads per second) or w/s (writes per second) values when writing large files.
What should I do if my disk shows 100% usage but I’m not using much storage?
Common silent storage bloat:
- Thumbnails: Linux creates thumbnails for images/views—clear them with:
rm -rf ~/.cache/thumbnails/ ~/.thumbnails/ - Download cache: Delete old downloads:
rm -rf ~/Downloads/*.zip ~/Downloads/*.tar.gz - System logs: Older logs are often full—use
journalctl --vacuum-time=1dto purge them. - Database files: If you use a database (e.g., MySQL), check:
sudo mysqladmin variables | grep tmp_table(look for largetmp_table_size). - Snapshots or Docker containers: If you use these, check their sizes:
docker system df(Docker) orsnap list(Snap packages).
Note: If you’re using a cloud instance or shared hosting, some space may be reserved by the provider (e.g., 10% for system usage). Check your hosting provider’s documentation for limits.