To check free disk space in Linux, you can use built-in commands like `df`—no extra tools or installations required. This simple command reveals the available space across your mounted filesystems, helping you avoid running out of storage or clean up unnecessary files. No special permissions are needed for basic use.

What You'll Need

  • A Linux system (Ubuntu, Fedora, Arch, Debian, or any modern distro).
  • Access to a terminal (most Linux desktops open one by default).
  • (Optional) A sudo user account (for advanced checks like checking root partitions).

Step-by-Step

  1. Open the terminal:
    • Press Ctrl+Alt+T (most Linux desktop environments).
    • Or search for "Terminal" in your applications menu.
  2. Run the basic disk space check: Use the df command without arguments to see disk usage for all mounted filesystems. Example output:
        Filesystem      Size  Used Avail Use% Mounted on
        /dev/sda1        50G   20G   25G  42% /
        tmpfs           3.9G     0  3.9G   0% /dev/shm
        
    What this shows: - The first column lists filesystems (e.g., /dev/sda1 is your root partition). - Size is total storage. - Used is how much is occupied. - Avail and Use% tell you how much is free and percentage used.
  3. Check a specific directory (e.g., `/home`): Use: df -h /home Flags explained: - -h formats output in human-readable units (GB, MB). - Replace /home with any path (e.g., /var for system files).
  4. Limit output to a single filesystem: Use: df /dev/sda1 (Replace /dev/sda1 with your actual partition, found in the first column of the first output.)
  5. Check for large files or processes (advanced): To find files consuming most space in /home: sudo du -sh * | sort -rh Flags explained: - du estimates disk usage. - -s shows total size per directory. - -h human-readable. - sort -rh sorts in reverse (largest first) by human-readable values. - sudo required (use without if you’re in /home).

Common Mistakes

  • Ignoring the filesystem name: Linux uses /dev/sda1, not just sda. Always use the full path from the df output to avoid errors. Fix: Run lsblk to list all partitions (e.g., sda, sdb, nvme0n1), then check df for the exact path.
  • Using -h without arguments: The -h flag alone doesn’t work. Always combine it with a path (e.g., df -h /).
  • Running du on the root partition: du / may return unreliable results on newer filesystems due to metadata caching. Use df instead. Fix: Stick to df for root-level checks.
  • Not checking for swap space: Linux also uses swap partitions. Run free -h to see swap usage alongside physical disks.

Tips

  • Compare partitions: Use df -h to list all mounted filesystems at once. Look for partitions with Use% close to 100%. Example:
        Filesystem      Size  Used Avail Use% Mounted on
        /dev/nvme0n1p21 128G   50G   70G  42% /
        
    Pro tip: Mount your external drive as /mnt/external and run df -h /mnt/external to see its usage.
  • Use ncdu for interactive analysis: Install it with sudo apt install ncdu (Debian/Ubuntu) or pacman -S ncdu (Arch). It lets you navigate directories like a file manager and delete files directly.
  • Avoid df on non-Linux systems: This command is Linux-specific. On macOS, use df -h (but results differ slightly). On Windows, use the GUI or command: wmic logicaldisk get caption,freespace,size.
  • Monitor disk health: Combine df with smartctl -a /dev/sdX (install smartmontools first) to check for failing drives.

Troubleshooting

  • Command not found: Ensure your terminal has Linux tools in the path. Reboot or run: sudo update-alternatives --config gcc (for core tools) if missing. If still stuck: Check your distro’s package manager for df (it’s usually preinstalled).
  • Output shows "no such file or directory": This often means your filesystem isn’t mounted. Verify mount points with: mount | grep /dev/sdX Fix: - If missing, remount with sudo mount /dev/sdX /mnt/point. - If unsure, list all mounted devices with df -T (shows filesystem type).
  • Disk usage seems low but files exist: Check hidden directories (e.g., .cache, .thumbnails) or temporary files in: ls -la /tmp/* /var/log/* /var/cache/*
  • Slow performance? First rule out disk space with df -h. If enough space exists, check for: - iostat -x 1 (I/O wait) or dstat (system monitoring). - Corruption: Run fsck after a crash.

Frequently Asked Questions

1. How do I check free space on a specific filesystem (e.g., an external drive)?

Answer: Mount the drive first (e.g., mkdir /mnt/external; sudo mount /dev/sdb1 /mnt/external), then use df -h /mnt/external.

2. Why does df show 0 bytes free on my primary partition?

Answer: This often means the filesystem is full. Run df -h to see if other partitions have space. If the system refuses to boot, check logs with journalctl -b for errors.

3. Can I check free space without admin rights?

Answer: Yes! Run df -h as any user. For directories like /home, use du -sh without sudo. Avoid df on root partitions unless you’re an admin.

4. How do I find the largest files on my system?

Answer: Use: sudo du -ahx / | sort -rh | head -n 10 This lists the top 10 largest files/directories. Replace / with /home if you want to focus there.

5. What if my disk shows "Use%" at 100% but I think I have space?

Answer: Common culprits: - Hidden files (e.g., ~/.cache). - System logs or old kernels (check /var/log/*, /var/cache/*). - Swap space misconfiguration (run free -h).

6. How do I clear temporary files to free up space?

Answer: Delete them manually: rm -rf ~/.cache/* For system-wide temps: sudo apt clean (Debian/Ubuntu) or sudo dnf clean all (Fedora/RHEL). ⚠️ Warning: Removing /var/log/* may cause system errors—use sparingly.