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
- Open your terminal or command prompt.
- Windows: Press
Win + R, typecmdorpowershell, then hit Enter. For multi-window support, installWindows Terminalfrom Microsoft Store. - macOS/Linux: Open Terminal directly from your Applications folder or by pressing
Cmd + Spaceand 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.
- Windows: Press
- Run the basic disk usage command.
For Linux/macOS, type:
df -hThis 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, HealthStatusfor basic drive health, orwmic logicaldisk get caption, freaspace,freespace /format:listfor free space per drive. Note: PowerShell’s output is less readable than Linux/macOS, so pipe toFormat-Listfor clarity. - Focus on your primary drive (e.g., / or C:).
- On Linux/macOS, filter the output with
df | grep '/dev/sdX'(replacesdXwith 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:).
- On Linux/macOS, filter the output with
- 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: UseGet-WmiObject Win32_LogicalDisk | Where-Object {$_.DriveType -eq 3} | Select-Object DeviceID, Size, FreeSpacefor detailed disk stats.
If That Did Not Work
- 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.
- Check for hardware issues.
If drives appear corrupted (e.g., -ve free space), run:
sudo fsck(Linux) or check Windows’chkdskin Command Prompt. - Verify the drive is mounted.
On Linux/macOS, list mounts with
mount | grep '/dev/sd'—if a drive is unmounted, it won’t show indf.
Common Mistakes
- Using wrong drive letter.
On Windows,
C:might be a secondary drive; checkwmic logicaldiskto confirm the system drive. - Ignoring filesystem-specific quirks.
Ext4 (Linux) and NTFS (Windows) handle space differently—
df -his reliable for Linux, but Windows’Get-Diskmay 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.bashrcfor a shortcut. - Compare drives.
Run
df -htwice—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, FreeSpaceto 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/sdXmatches your actual drive (e.g.,sdavs.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:
- Press
Win + S, typeStorage. - Open
Storage settingsand selectFree 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.