Check Free Disk Space in Linux Terminal
In this article
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
sudoprivileges, but basic usage works without them.
Step-by-Step
- Open a terminal. Press
Ctrl+Alt+Ton most desktop environments, or search for "Terminal" in your applications menu. - Check overall disk space with
df. Typedf -hand press Enter. The-hflag 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. - Understand the
dfoutput. 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). - Check a specific mount point. If you want to see the disk usage for a particular drive or partition, use
df -h /home(replace/homewith your target path). This is useful when you have multiple drives. - View inodes (optional). Run
df -ito 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. - Check directory size with
du. To see how much space a directory and its contents use, typedu -sh /path/to/directory. The-sflag summarizes (only shows the total), and-hmakes it human-readable. For example,du -sh ~/Downloadsshows the size of your Downloads folder. - List the largest subdirectories. Run
du -h --max-depth=1 /pathto see the size of each subdirectory one level deep. This helps identify what's eating your disk. For a sorted list, usedu -h --max-depth=1 /path | sort -hr(thesort -hrsorts by human-readable size in reverse). - Combine with
sudofor full access. Some directories (like/varor/root) may not be readable by a normal user. Prefix withsudoto get complete stats:sudo du -sh /var.
Common Mistakes
- Forgetting the
-hflag. Without it, output is in 1K blocks, which is hard to read. Always use-hfor human-readable sizes. - Misreading
dfvsdu.dfshows free space on filesystems;dushows the size of directories and files. They answer different questions. - Using
duwithout-son large directories. Runningdu -h /homewill list every file and subdirectory, which can be overwhelming and slow. Use-sfor 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
dushows the same asdf. Deleted files still open by processes can hold space thatduwon't show butdfwill. Ifdfshows less free space than expected, check for open deleted files.
Tips
- Use
df -hTto 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'andalias du='du -h'to your~/.bashrcor~/.zshrcso you don't have to type the flag every time. - Use
ncdufor interactive browsing. If you want a visual, interactive way to explore disk usage, installncdu(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 -hto refresh the output every 5 seconds, useful when you're copying large files. - Remember that
ducounts 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
dforduare missing, your PATH may be broken. Try/bin/dfor/usr/bin/du. If they don't exist, your system is severely damaged; reinstall coreutils. - Permission denied. When running
duon a directory you don't own, you'll see errors. Usesudo du -sh /pathto bypass, or add2>/dev/nullto suppress error messages (e.g.,du -sh /path 2>/dev/null). - Output is in bytes despite
-h. Some older systems may not support-h; usedf -k(kilobytes) ordf -m(megabytes) as fallback. duis slow on large directories. This is normal because it scans every file. Use--max-depth=1to limit scanning, or run it in the background withdu -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
- What is the difference between
dfanddu?df(disk free) reports the free space on entire filesystems.du(disk usage) reports the size of directories and files. Usedfto see if a disk is full, andduto find what's filling it. - Why does
dushow more space used thandfshows available? This can happen becauseducounts files that are actually deleted but still open by processes, or because of filesystem overhead (reserved blocks, metadata). Also,dfshows the filesystem's view, which may include reserved space for root. - How do I check free space on a specific drive? Use
df -h /mount/point, replacing/mount/pointwith the actual mount point (e.g.,/homeor/media/usb). You can find mount points by runningdf -hwithout arguments. - Can I see disk usage in real-time? Yes, use
watch -n 2 df -hto refresh every 2 seconds. For directory sizes, you can combinewatchwithdu, but be aware thatducan be slow on large directories. - How do I find the largest files on my system? Use
du -a /path | sort -n -r | head -20to list the top 20 largest files. Addsudoto scan system directories. Alternatively, usefind / -type f -size +100Mto find files larger than 100MB. - 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.