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+T on 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

  1. Basic Disk Usage Summary with df Run this command to see all mounted filesystems and their free space: df -h

    Breakdown 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), and 100% (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/shm

    If / (root) is at 100%, you likely need to clean up logs, cached files, or swap space. Check for large directories later with du.

  2. Check Disk Usage per Directory with du Use this to scan large directories for hidden storage bloat: du -sh /path/to/directory

    Flags explained:**

    • -s: Show summary (total size of the directory).
    • -h: Human-readable format.

    Examples:**

    • Check the /home directory: 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).

  3. List Disks and Partitions with lsblk Identify your physical disks and partitions (useful for checking external drives or errors): lsblk -f

    Example output:** NAME FSTYPE SIZE MOUNTPOINT sda ntfs 500G /media/data sda1 ext4 12G / sdb vfat 512M /boot/efi

    Compare this to df to see which partitions are mounted and their usage. If sda shows unallocated space but df doesn’t list it, the filesystem might be corrupted (see troubleshooting).

  4. Check Specific Files or Directories Use ls or stat for 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.
  5. Identify Large Files with find Find 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 -h flag in df or du.

    Without -h, you’ll see numbers like 3221225472 (bytes), making it hard to interpret. Always use it for readability.

  • Using df for local directories.

    df only shows mounted filesystems, not directories on the same filesystem. For local paths, use du instead.

  • Not sorting large directories with du. Run du -ahx /path | sort -rh to list directories from largest to smallest. Without sorting, you might miss the biggest culprits.
  • Assuming sda1 is the root partition. Partitions can be labeled differently (e.g., /dev/nvme0n1p2 or sdb1 for external drives). Check lsblk to confirm.

Tips

  • Automate disk checks with cron. Add this to your crontab -e to run df -h daily at 2 AM: 0 2 * * * df -h

    Log results to a file for monitoring: 0 2 * * * df -h >> /var/log/disk_usage.log

  • Use ncdu for an interactive tool. Install it with: sudo apt install ncdu (Debian/Ubuntu) or sudo 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 (df shows "Swap:"), but it’s not a real disk. Free space with: free -h → Look for Swap: under "Mem:" (if swap is active).
  • Clear temporary files early. Remove caches with: sudo apt clean (Debian) or sudo 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=1 for a quick scan. Run this once to see top-level directory sizes: du --max-depth=1 / | sort -rh

    This replaces du -h for an overview.

Troubleshooting

If commands don’t display expected output (e.g., no space shows up in df), follow these steps in order:

  1. Restart the system. A sudden drop in disk space may be due to a kernel or filesystem error. Log off and reboot.
  2. Check for corrupted filesystems. Run sudo fsck (for root) or sudo fsck /dev/sdX1 (replace X with your partition, e.g., sda1): sudo fsck -f /dev/sda1

    Warning:** This may require ejecting physical drives if the filesystem is corrupted. Never run fsck on a mounted partition.

  3. Verify disk partitions with fdisk. If lsblk shows unallocated space but df doesn’t list it, the partition table might be misconfigured: sudo fdisk -l

    Look for entries like [empty) under "Size." If you find them, your system may not recognize the disk properly.

  4. Check for disk errors with smartctl. Install it with: sudo apt install smartmontools

    Test disk health: sudo smartctl -a /dev/sda

    Look for warnings like Reallocated_Sector_Ct (indicating bad sectors). If the disk is failing, back up critical data immediately.

  5. Reinstall the filesystem (last resort). If you suspect a filesystem corruption that fsck can’t repair, you may need to reinstall it:
    • For ext4 (most common): sudo mkfs.ext4 /dev/sda1 (replace sda1 with your partition).

      Warning:** This will erase all data on the partition. Backup first!

    • For NTFS (Windows drives): Use tools like ntfsfix (Linux) or a Windows tool like chkdsk.

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/tmp to clear old logs with rm -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=100M to purge old logs.

How do I see which files are taking up the most space in a directory?

Use a multi-step approach:

  1. First, get a high-level overview: du -ahx /path/to/directory | sort -rh | head -n 20 (shows top 20 largest files).
  2. 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

  1. If it’s ext4, the partition may be full but not yet at 100% (use df -i to check inodes).
  2. If it’s a swap partition, df won’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:

  1. Install sysstat with: sudo apt install sysstat (Debian) or sudo dnf install sysstat (Fedora).
  2. 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=1d to purge them.
  • Database files: If you use a database (e.g., MySQL), check: sudo mysqladmin variables | grep tmp_table (look for large tmp_table_size).
  • Snapshots or Docker containers: If you use these, check their sizes: docker system df (Docker) or snap 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.