The first step to managing your Linux system efficiently is checking disk space usage. This tells you how much space is taken by files, folders, and system files, helping you identify large files, free up disk space, or diagnose storage issues. You’ll need at least basic Linux terminal access (root or a user with sudo privileges) for most methods. No special tools are required beyond what comes pre-installed on most Linux distributions.

What You'll Need

  • The Linux terminal (accessed via keyboard shortcut like Ctrl+Alt+T on most desktop environments)
  • Root or sudo access to run certain disk queries (especially for system-level checks)
  • A Linux distribution (Ubuntu, Fedora, Arch Linux, etc.)—commands work similarly across distros, but some options may vary slightly between versions
  • Optional: A graphical file manager (like Nautilus/GNOME Files, Dolphin, or Thunar) if you prefer a visual approach

Step-by-Step

  1. Use the df command for a high-level disk usage summary. Run this in the terminal to see all mounted file systems and their usage: df -h - The output shows disk space for each partition, including root (/), home (~), and any external drives. - Columns include:
    • Filesystem: The partition name (e.g., /dev/sda1)
    • Size: Total space allocated
    • Used: Space currently in use
    • Avail: Available space
    • Use%: Percentage used
    - Example output: Filesystem Size Used Avail Use% Mounted on /dev/sda1 50G 30G 19G 61% / tmpfs 3.9G 0 3.9G 0% /dev/shm - If a partition shows Use% = 100%, it’s full and likely blocking new installations or updates.
  2. Use du to inspect space usage by specific directories. Run du -sh /path/to/directory to check disk usage for a folder (replace /path/to/directory with the actual path). - The -s flag sums the space used by the directory alone, while -h displays sizes in human-readable format (GB, MB, etc.). - Example: du -sh ~/Downloads shows space used by the Downloads folder. - To list space usage for subdirectories within a folder, omit -s: du -h /var/log - Use sort -rh to sort results by largest usage: du -hx /home | sort -rh | head -n 10 (The x flag skips directories named . and ...)
  3. Use ncdu for an interactive, user-friendly disk analyzer (install if missing).

    Install ncdu via your package manager (e.g., sudo apt install ncdu on Debian/Ubuntu) or pacman -S ncdu on Arch Linux. After installation, run ncdu /path/to/directory (e.g., ncdu ~/Documents).

    • ncdu provides a text-based interface with color-coded usage (green for free space, red for high usage).
    • Use arrow keys to navigate, then press d to delete files/folders (use with caution!).
    • Press q to quit.

    For system-wide analysis, run ncdu / (requires root/sudo).

  4. Check for large files or directories with find. Run find /path/to/search -type f -exec ls -lh {} + | grep -E "(GB|TB)" to list files larger than 1GB in a directory. - For example: find ~/Downloads -type f -size +1G finds all files >1GB in the Downloads folder. - Replace +1G with +50M to filter for files >50MB. - To exclude hidden files, add -not -path '*/.*': find /var -type f -exec ls -lh {} + | grep -E "(GB|TB)" -v
  5. Use lsblk to inspect block devices and partitions. Run lsblk to list all block devices (disks and partitions) with their sizes. - Example output: NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT sda 8:0 0 500G 0 disk └─sda1 8:1 0 50G 0 part / nvme0n1 259:0 0 1.8T 0 disk └─nvme0n1p1 259:1 0 500M 0 part /boot/efi - Helps identify which partition is full or if you’re using a larger disk than expected.
  6. Disable swap space if not needed. Check swap usage with free -h. If your system has swap but you’re low on disk space:
    1. Disable swap at boot by removing it from /etc/fstab:
      • Edit the file: sudo nano /etc/fstab
      • Find the swap line (e.g., /dev/sda2 none swap sw pri=10) and comment it out by adding a # at the start.
      • Save (Ctrl+O, then Enter) and exit (Ctrl+X).
    2. Reboot to apply changes.

    Note: This reduces memory for applications but may cause slowdowns if swap is heavily used.

Common Mistakes

  • Misinterpreting df output. The Use% column shows percentage used, not remaining space. For example, 61% usage means 39% free, not 40% free. Use df -h to check actual sizes.
  • Running du on system directories without root. Directories like /var or /home require root privileges. Use sudo du -h /var if needed.
  • Deleting critical system files. If you accidentally delete a file (e.g., a config or log), recover it from:
    • ~/.local/share/Trash (user trash folder)
    • /var/log (system logs)

    For permanent data loss, use testdisk or photorec from the terminal.

  • Ignoring space from applications. Services like Docker, systemd, or browser cache use disk space. Check /var/lib and /home/username/.cache for hidden data.

Tips

  • Set up disk space alerts. Use watch to monitor usage over time: watch -n 5 'df -h' (Refreshes every 5 seconds.) For a scripted alert, use a cron job to check df and email you if usage exceeds 90%.
  • Use old files first. Before deleting large files, check their age with: ls -lh /path/to/directory | grep | awk '{print $5} Delete oldest files first to avoid accidental data loss.
  • Compress large directories. Use tar -czvf compressed.tar.gz /path/to/directory to compress a folder into a single file.
  • Avoid deleting system files. Critical files are in /etc, /boot, and /lib. Use apt autoremove (Debian/Ubuntu) or dnf autoremove (Fedora) to clean system packages instead.
  • Use cloud storage. If you’re low on disk space, back up important files to cloud services like Nextcloud, Dropbox, or Google Drive.

Troubleshooting

If the above commands fail or don’t show expected results, try these steps:

  1. Check for disk errors. Run a filesystem check with: sudo fsck -f /dev/sdX - Replace sdX with your actual disk partition (e.g., sda1). - If the disk is full, skip this step or run it later after freeing space.
  2. Restart the system. A simple reboot can refresh disk usage metrics: sudo reboot - Wait a minute for the OS to update its disk stats.
  3. Update the system and tools. Outdated tools may not display accurate results: sudo apt update && sudo apt upgrade (Debian/Ubuntu) sudo dnf update (Fedora) sudo pacman -Syu (Arch Linux)
  4. Check for files in use. If a directory shows full space but is unused, files inside may be locked: lsof | grep - Try deleting the file manually if no processes are using it.
  5. Reinstall disk utilities. If commands like df or du behave strangely, reinstall them: sudo apt install --reinstall coreutils df du (Debian/Ubuntu)
  6. Verify disk space with GUI tools. If terminal commands fail, use a graphical file manager (e.g., nautilus on GNOME) to inspect disk usage visually.

Frequently Asked Questions

How do I see which files are using the most space in Linux?

Use ncdu (install with sudo apt install ncdu) or a terminal command like: du -sh /home/* | sort -rh | head -n 5 This lists the top 5 largest directories in the home folder.

Why is my disk full even though I deleted files?

Hidden files, system caches, or temporary files (e.g., in /tmp, /.cache) may still occupy space. Check with: du -sh ~/.cache du -sh /tmp or run ncdu to explore all areas.

How can I free up space permanently?

Permanent solutions include: - Deleting old/unnecessary files (e.g., downloads, logs). - Using apt autoremove (Debian/Ubuntu) to clean unused packages. - Compressing large directories into .tar.gz files. - Moving large files to cloud storage.

Does Linux show disk usage for external drives?

Yes. Run df -h to see external drives (e.g., USB, SD cards) listed under their mount point (like /media/username/USB_Drive). If unmounted, use: lsblk to see connected disks, then mount them manually.

Why is my root partition full when I’m the only user?

Root partitions often store system logs, caches, and temp files. Check: du -sh /var/log du -sh /tmp Use journalctl to review system logs for large files.

Can I check disk usage on a remote Linux server via SSH?

Yes. Run: df -h du -sh /home/* On commands may require SSH key-based authentication (no password prompts). Use scp to transfer large files from the server to your local machine if needed.