To check free disk space in Linux, you can use built-in commands like `df`—no extra tools or installations required. This simple command reveals the available space across your mounted filesystems, helping you avoid running out of storage or clean up unnecessary files. No special permissions are needed for basic use.
What You'll Need
- A Linux system (Ubuntu, Fedora, Arch, Debian, or any modern distro).
- Access to a terminal (most Linux desktops open one by default).
- (Optional) A sudo user account (for advanced checks like checking root partitions).
Step-by-Step
- Open the terminal:
- Press
Ctrl+Alt+T(most Linux desktop environments). - Or search for "Terminal" in your applications menu.
- Press
- Run the basic disk space check:
Use the
dfcommand without arguments to see disk usage for all mounted filesystems. Example output:Filesystem Size Used Avail Use% Mounted on /dev/sda1 50G 20G 25G 42% / tmpfs 3.9G 0 3.9G 0% /dev/shmWhat this shows: - The first column lists filesystems (e.g.,/dev/sda1is your root partition). -Sizeis total storage. -Usedis how much is occupied. -AvailandUse%tell you how much is free and percentage used. - Check a specific directory (e.g., `/home`):
Use:
df -h /homeFlags explained: --hformats output in human-readable units (GB, MB). - Replace/homewith any path (e.g.,/varfor system files). - Limit output to a single filesystem:
Use:
df /dev/sda1(Replace/dev/sda1with your actual partition, found in the first column of the first output.) - Check for large files or processes (advanced):
To find files consuming most space in
/home:sudo du -sh * | sort -rhFlags explained: -duestimates disk usage. --sshows total size per directory. --hhuman-readable. -sort -rhsorts in reverse (largest first) by human-readable values. -sudorequired (use without if you’re in/home).
Common Mistakes
- Ignoring the filesystem name:
Linux uses
/dev/sda1, not justsda. Always use the full path from thedfoutput to avoid errors. Fix: Runlsblkto list all partitions (e.g.,sda, sdb, nvme0n1), then checkdffor the exact path. - Using
-hwithout arguments: The-hflag alone doesn’t work. Always combine it with a path (e.g.,df -h /). - Running
duon the root partition:du /may return unreliable results on newer filesystems due to metadata caching. Usedfinstead. Fix: Stick todffor root-level checks. - Not checking for swap space:
Linux also uses swap partitions. Run
free -hto see swap usage alongside physical disks.
Tips
- Compare partitions:
Use
df -hto list all mounted filesystems at once. Look for partitions withUse%close to 100%. Example:Filesystem Size Used Avail Use% Mounted on /dev/nvme0n1p21 128G 50G 70G 42% /Pro tip: Mount your external drive as/mnt/externaland rundf -h /mnt/externalto see its usage. - Use
ncdufor interactive analysis: Install it withsudo apt install ncdu(Debian/Ubuntu) orpacman -S ncdu(Arch). It lets you navigate directories like a file manager and delete files directly. - Avoid
dfon non-Linux systems: This command is Linux-specific. On macOS, usedf -h(but results differ slightly). On Windows, use the GUI or command:wmic logicaldisk get caption,freespace,size. - Monitor disk health:
Combine
dfwithsmartctl -a /dev/sdX(installsmartmontoolsfirst) to check for failing drives.
Troubleshooting
- Command not found:
Ensure your terminal has Linux tools in the path. Reboot or run:
sudo update-alternatives --config gcc(for core tools) if missing. If still stuck: Check your distro’s package manager fordf(it’s usually preinstalled). - Output shows "no such file or directory":
This often means your filesystem isn’t mounted. Verify mount points with:
mount | grep /dev/sdXFix: - If missing, remount withsudo mount /dev/sdX /mnt/point. - If unsure, list all mounted devices withdf -T(shows filesystem type). - Disk usage seems low but files exist:
Check hidden directories (e.g.,
.cache,.thumbnails) or temporary files in:ls -la /tmp/* /var/log/* /var/cache/* - Slow performance?
First rule out disk space with
df -h. If enough space exists, check for: -iostat -x 1(I/O wait) ordstat(system monitoring). - Corruption: Runfsckafter a crash.
Frequently Asked Questions
1. How do I check free space on a specific filesystem (e.g., an external drive)?
Answer: Mount the drive first (e.g.,mkdir /mnt/external; sudo mount /dev/sdb1 /mnt/external), then use df -h /mnt/external.
2. Why does df show 0 bytes free on my primary partition?
Answer: This often means the filesystem is full. Run df -h to see if other partitions have space. If the system refuses to boot, check logs with journalctl -b for errors.
3. Can I check free space without admin rights?
Answer: Yes! Rundf -h as any user. For directories like /home, use du -sh without sudo. Avoid df on root partitions unless you’re an admin.
4. How do I find the largest files on my system?
Answer: Use:sudo du -ahx / | sort -rh | head -n 10
This lists the top 10 largest files/directories. Replace / with /home if you want to focus there.
5. What if my disk shows "Use%" at 100% but I think I have space?
Answer: Common culprits: - Hidden files (e.g.,~/.cache).
- System logs or old kernels (check /var/log/*, /var/cache/*).
- Swap space misconfiguration (run free -h).
6. How do I clear temporary files to free up space?
Answer: Delete them manually:rm -rf ~/.cache/*
For system-wide temps:
sudo apt clean (Debian/Ubuntu) or sudo dnf clean all (Fedora/RHEL).
⚠️ Warning: Removing /var/log/* may cause system errors—use sparingly.