Smart Systems for Home

Plain how-to guides for smart home, security and home Wi-Fi

Check Free Disk Space in Linux Terminal

· 5 min read · Home Tech

In this article
  1. What You'll Need
  2. Step-by-Step
  3. Common Mistakes
  4. Tips
  5. Troubleshooting
  6. Frequently Asked Questions

This guide shows you how to check free disk space and disk usage directly from the Linux command line. You'll learn the essential df and du commands, how to read their output, and how to interpret the numbers to keep your system healthy. No special tools are required—just a terminal and a basic user account.

What You'll Need

  • A Linux system with a terminal emulator (e.g., GNOME Terminal, Konsole, or a simple TTY).
  • A user account with read permissions for the directories you want to inspect (most home directories are fine).
  • For system-wide disk stats, you may need sudo privileges, but basic usage works without them.

Step-by-Step

  1. Open a terminal. Press Ctrl+Alt+T on most desktop environments, or search for "Terminal" in your applications menu.
  2. Check overall disk space with df. Type df -h and press Enter. The -h flag makes the output human-readable (shows sizes in KB, MB, GB instead of raw bytes). You'll see a table with columns: Filesystem, Size, Used, Avail, Use%, and Mounted on.
  3. Understand the df output. The "Filesystem" column shows device names (like /dev/sda1). "Size" is total capacity, "Used" is space consumed, "Avail" is free space, "Use%" is the percentage used, and "Mounted on" is where the filesystem is attached (e.g., / for root).
  4. Check a specific mount point. If you want to see the disk usage for a particular drive or partition, use df -h /home (replace /home with your target path). This is useful when you have multiple drives.
  5. View inodes (optional). Run df -i to see inode usage. Inodes are data structures that store file metadata; if they run out, you can't create new files even if space remains. This is rare but worth knowing.
  6. Check directory size with du. To see how much space a directory and its contents use, type du -sh /path/to/directory. The -s flag summarizes (only shows the total), and -h makes it human-readable. For example, du -sh ~/Downloads shows the size of your Downloads folder.
  7. List the largest subdirectories. Run du -h --max-depth=1 /path to see the size of each subdirectory one level deep. This helps identify what's eating your disk. For a sorted list, use du -h --max-depth=1 /path | sort -hr (the sort -hr sorts by human-readable size in reverse).
  8. Combine with sudo for full access. Some directories (like /var or /root) may not be readable by a normal user. Prefix with sudo to get complete stats: sudo du -sh /var.

Common Mistakes

  • Forgetting the -h flag. Without it, output is in 1K blocks, which is hard to read. Always use -h for human-readable sizes.
  • Misreading df vs du. df shows free space on filesystems; du shows the size of directories and files. They answer different questions.
  • Using du without -s on large directories. Running du -h /home will list every file and subdirectory, which can be overwhelming and slow. Use -s for a summary.
  • Ignoring the "Use%" column. If it's near 100%, you may run out of space soon, even if "Avail" looks large on a small filesystem.
  • Assuming du shows the same as df. Deleted files still open by processes can hold space that du won't show but df will. If df shows less free space than expected, check for open deleted files.

Tips

  • Use df -hT to also display the filesystem type (ext4, xfs, etc.) in the output. This helps identify network mounts or special filesystems.
  • Create aliases. Add alias df='df -h' and alias du='du -h' to your ~/.bashrc or ~/.zshrc so you don't have to type the flag every time.
  • Use ncdu for interactive browsing. If you want a visual, interactive way to explore disk usage, install ncdu (via your package manager) and run it on a directory. It's not standard, but it's a huge time-saver.
  • Check disk space in real-time. Use watch -n 5 df -h to refresh the output every 5 seconds, useful when you're copying large files.
  • Remember that du counts hard links multiple times. If you have hard-linked files, they appear in each directory, inflating the total. This is rare but can confuse.

Troubleshooting

  • Command not found. If df or du are missing, your PATH may be broken. Try /bin/df or /usr/bin/du. If they don't exist, your system is severely damaged; reinstall coreutils.
  • Permission denied. When running du on a directory you don't own, you'll see errors. Use sudo du -sh /path to bypass, or add 2>/dev/null to suppress error messages (e.g., du -sh /path 2>/dev/null).
  • Output is in bytes despite -h. Some older systems may not support -h; use df -k (kilobytes) or df -m (megabytes) as fallback.
  • du is slow on large directories. This is normal because it scans every file. Use --max-depth=1 to limit scanning, or run it in the background with du -sh /bigdir & and check later.
  • Filesystem shows 100% but you can't find large files. This often happens due to deleted files still held open by a process. Use lsof +L1 (as root) to list them, then restart the process to free the space.

Frequently Asked Questions

  1. What is the difference between df and du? df (disk free) reports the free space on entire filesystems. du (disk usage) reports the size of directories and files. Use df to see if a disk is full, and du to find what's filling it.
  2. Why does du show more space used than df shows available? This can happen because du counts files that are actually deleted but still open by processes, or because of filesystem overhead (reserved blocks, metadata). Also, df shows the filesystem's view, which may include reserved space for root.
  3. How do I check free space on a specific drive? Use df -h /mount/point, replacing /mount/point with the actual mount point (e.g., /home or /media/usb). You can find mount points by running df -h without arguments.
  4. Can I see disk usage in real-time? Yes, use watch -n 2 df -h to refresh every 2 seconds. For directory sizes, you can combine watch with du, but be aware that du can be slow on large directories.
  5. How do I find the largest files on my system? Use du -a /path | sort -n -r | head -20 to list the top 20 largest files. Add sudo to scan system directories. Alternatively, use find / -type f -size +100M to find files larger than 100MB.
  6. Is there a GUI alternative? Yes, tools like GNOME Disks, KDE Partition Manager, or the disk usage analyzer (baobab) provide graphical views. But the terminal commands are faster and work on headless servers.