In Linux, checking disk space is effortless—just use one of several built-in commands. These commands reveal whether your system has enough storage for files, apps, or temporary caches. No extra software is required, and the results appear instantly. The simplest method is `df`, but `du` is ideal for deep filesystem scans, while `du -h` provides human-readable sizes for quick assessments. These commands work on any Linux distribution without configuration.

What You'll Need

  • A functioning Linux terminal (or a GUI tool like Files/Nautilus on desktop systems).
  • Basic familiarity with command-line syntax (e.g., typing commands and interpreting outputs).
  • Permissions to run commands (no extra tools needed).

Step-by-Step

  1. Use `df` for overall partition space (fastest overview): Open your terminal and type: df -h. This command shows disk space for every mounted filesystem, formatted in human-readable units (GB/KB). Columns include:
    • /dev/sdX: Device (e.g., /dev/sda1 for root).
    • Filesystem: Where files are stored (e.g., /, /home).
    • Size: Total space.
    • Used: Space in use.
    • Avail: Free space.
    • Use%: Percentage used.
    Example output: Filesystem Size Used Avail Use% Mounted on /dev/sda1 50G 10G 40G 20% / Key check: If Use% is near 100%, your system is running low on space.
  2. Use `du` to inspect directory sizes (detailed lookup): Navigate to a folder (e.g., your home directory) and run: du -sh /path/to/directory. Replace /path/to/directory with the folder you want to scan.
    • -s: Summarize total size (skip subdirectories).
    • -h: Show sizes in human-readable format (e.g., 1G, 200M).
    Example: du -sh /var/log reveals the size of the system logs. For deeper analysis: Add --max-depth=1 to limit scans to immediate subdirectories: du --max-depth=1 -h /home.
  3. Check specific files/folders: To see the size of a single file, use: ls -lh filename. To find large files in a directory, run: sudo find /path/to/dir -type f -exec du -h {} +. Warning: Running without `sudo` may return only user-accessible files.

Common Mistakes

  • Ignoring hidden files/directories: Commands like `du` omit hidden files (e.g., .cache or .thumbnails) by default. To include them, add the -a flag: du -ah /home.
  • Not filtering output: To focus on a specific filesystem (e.g., /home), use `df` with a filter: df | grep "/home". This highlights only entries for the /home partition.
  • Misinterpreting `df` vs. `du`: df shows overall partition usage, while du measures folder/file sizes. Mixing them can lead to confusion (e.g., checking a file’s size with `df`).
  • Running as root without need: Use `sudo` only if necessary (e.g., to check system-wide files). Unnecessary root access can hide sensitive space issues.

Tips

  • Automate with cron: Schedule regular disk checks (e.g., daily) with a cron job: 0 3 * * * df -h >> /var/log/disk_check.log. This logs results to a file for review.
  • Use `ncdu` for interactive scans: Install ncdu (a GUI-like tool) via package managers (e.g., sudo apt install ncdu on Debian). Navigate with arrow keys, sort by size, and delete files effortlessly.
  • Watch for temporary files: Large sizes in `/tmp` or `/var/tmp` often indicate processes using disk space. Close applications or clear cache with: rm -rf /tmp/* (be careful!).
  • Compare before/after: Run `df` before and after freeing space (e.g., deleting logs). Example: df -h (before) → rm /var/log/oldlogs/* → df -h (after).

Troubleshooting

  • Commands return no output: Ensure the directory exists. If using du, try a known folder (e.g., /bin): du -sh /bin. If the terminal freezes, check for network issues or disk errors with sudo dmesg.
  • Results show "No Space Left On Device": This is an error, not false data. Free space by:
    1. Deleting old files (e.g., backups, logs): sudo rm -rf /path/to/files.
    2. Expanding the filesystem (advanced): Use resize2fs for ext4 partitions (requires sudo).
    3. Mounting a larger drive (if available).
  • Commands slow down performance: Large scans (e.g., du -sh /) can lock up the system. Limit depth or use a smaller directory: du --max-depth=2 -h /var.
  • No output from `df`: Check if the filesystem is mounted elsewhere (e.g., via LVM or network). Use mount to list mounts: mount | grep /dev/sdX.

Frequently Asked Questions

How do I check disk space using GUI tools?

On desktop Linux (e.g., GNOME/KDE), use the file manager (Files/Nautilus). Right-click a folder, select Properties>, then check the "Disk Usage" tab. For system-wide checks, go to Settings > System > Storage. These tools show space visually but lack the granularity of terminal commands.

Why does `df` show 0% used for a mounted partition?

This can occur if the files are stored in an off-mounted location (e.g., a remote drive or cloud sync) or if the filesystem is corrupted. Run sudo fsck to verify the partition or check for network-mounted files (e.g., SSH/FTP).

How can I find the largest files in my home directory?

Use this one-liner to sort files by size (descending): ls -lSh /home/*/ | tail -20. For a single directory, replace /home/*/ with the target path (e.g., /home/youruser/Downloads).

Will these commands work on macOS or Windows?

These commands are Linux-specific. On macOS, use df -h (BSD-style) or GUI tools like Disk Utility. On Windows, use File Explorer or wmic logicaldisk get size,freespace.

How do I clear temporary files to free up space?

For Linux, use: sudo apt autoremove (Debian/Ubuntu) to clean package cache, or manually delete /tmp or /var/tmp. Avoid deleting critical files (e.g., from /boot).

Can I check disk space for a specific user?

Yes, but permissions matter. Run: du -sh /home/username. For system-wide checks (requires root), use: sudo du -sh /home/*. Use caution with root commands.