On nearly every computer or server, the fastest way to check disk space is via the command line. Whether you’re running Linux, macOS, or Windows, these tools let you see exactly how much free space remains on drives—critical for avoiding crashes, deleting files, or troubleshooting storage issues. No extra software needed; just open a terminal (or Command Prompt) and run a simple command. Here’s how to do it right.

What You'll Need

  • A working terminal or command prompt—Windows users should use Windows Terminal or Command Prompt, macOS/Linux users can open Terminal directly.
  • Basic familiarity with terminal commands (optional but helpful for deeper checks).

Step-by-Step

  1. Open your terminal or command prompt.
    • Windows: Press Win + R, type cmd or powershell, then hit Enter. For multi-window support, install Windows Terminal from Microsoft Store.
    • macOS/Linux: Open Terminal directly from your Applications folder or by pressing Cmd + Space and typing "Terminal."

    If you don’t have a terminal, check if your OS has a built-in disk checker (e.g., macOS’s "About This Mac" or Windows’ "This PC" tab)—but these don’t show detailed command-line results.

  2. Run the basic disk usage command. For Linux/macOS, type: df -h

    This shows all mounted filesystems with these columns: Filesystem (mount point), Size (total), Used, Avail (free), Use%, Mounted on.

    Windows (PowerShell): Run: Get-Disk | Select-Object Number, Size, HealthStatus for basic drive health, or wmic logicaldisk get caption, freaspace,freespace /format:list for free space per drive. Note: PowerShell’s output is less readable than Linux/macOS, so pipe to Format-List for clarity.

  3. Focus on your primary drive (e.g., / or C:).
    • On Linux/macOS, filter the output with df | grep '/dev/sdX' (replace sdX with your drive, e.g., sda1). For your home directory (~), use: du -sh ~

      This shows ~’s total size. To check subfolders (e.g., Documents), run: du -sh ~/Documents

    • On Windows, list drives with wmic logicaldisk get caption, size, free. Highlight your system drive (e.g., C:).
  4. Check for critical thresholds.

    A healthy system typically has at least 10% free space on the root/filesystem drive (/ in Linux/macOS, C: in Windows). Run: df -h | grep 'Use%' (Linux/macOS) to see if any drive exceeds, say, 80% usage. Windows tip: Use Get-WmiObject Win32_LogicalDisk | Where-Object {$_.DriveType -eq 3} | Select-Object DeviceID, Size, FreeSpace for detailed disk stats.

If That Did Not Work

  1. Restart your terminal or system. Closed and reopened windows often refresh disk checks. On Linux/macOS, try restarting the system if the command returns "no space left" errors.
  2. Check for hardware issues. If drives appear corrupted (e.g., -ve free space), run: sudo fsck (Linux) or check Windows’ chkdsk in Command Prompt.
  3. Verify the drive is mounted. On Linux/macOS, list mounts with mount | grep '/dev/sd'—if a drive is unmounted, it won’t show in df.

Common Mistakes

  • Using wrong drive letter. On Windows, C: might be a secondary drive; check wmic logicaldisk to confirm the system drive.
  • Ignoring filesystem-specific quirks. Ext4 (Linux) and NTFS (Windows) handle space differently—df -h is reliable for Linux, but Windows’ Get-Disk may miss small drives.
  • Overlooking temporary files. Run du -sh /tmp (Linux/macOS) or check %TEMP% (Windows) for hidden storage hogs.

Tips

  • Monitor over time. Schedule disk checks with cron (Linux/macOS) or Task Scheduler (Windows) to spot trends early.
  • Use aliases. Linux/macOS users: Add alias df='df -h' to .bashrc for a shortcut.
  • Compare drives. Run df -h twice—note changes between sessions (e.g., downloads or backups).
  • Windows tip: Exclude system files. Use Get-WmiObject Win32_LogicalDisk | Where-Object {$_.DriveType -eq 3} | Select-Object DeviceID, Size, FreeSpace to see only user-accessible drives.

Troubleshooting

  • Commands return "permission denied" (Linux/macOS). Run with sudo df -h (use your user password). For non-root checks, ensure the drive is readable from your user account.
  • Disk shows negative free space. The drive may be corrupted or improperly formatted. Boot into a live USB, run fsck, or replace the drive.
  • No drives appear in output. Double-check your terminal is connected to the correct network share or local drive. On Linux, ensure /dev/sdX matches your actual drive (e.g., sda vs. sdb).

Frequently Asked Questions

1. How do I check disk space on a remote Linux server via SSH?

Run the same commands over SSH: df -h or du -sh /path/to/dir. Ensure SSH has read access to the directory.

2. Why does my Windows command show 0 free space when the GUI says otherwise?

The GUI (This PC) may cache data or show cached stats. Use wmic logicaldisk get freaspace,freespace /format:list for accurate, real-time results.

3. Can I check disk usage for a specific folder on macOS?

Yes: du -sh /path/to/folder gives the folder’s size. For recursive checks (including subfolders), add -s:

du -sh --max-depth=1 ~/Documents

Note: Use --max-depth=1 to limit depth to avoid overwhelming output.

4. What if my Linux terminal says "no space left" but I see files?

Files may be on a different partition or swap space. Check with df -h for the correct filesystem. If files are missing, the drive might be full on a logical partition.

5. How do I clear old logs to free up space on a Windows PC?

Use Windows Search:

  1. Press Win + S, type Storage.
  2. Open Storage settings and select Free up space now.

    Alternative: Delete logs manually in C:\Windows\Logs.

6. My Linux terminal shows 100% used, but my system still runs fine.

Modern systems can tolerate slight overuse, especially if free space is on a separate partition. Check with df -h to confirm where the space is consumed.