How to Check Disk Space on Ubuntu: df, du and the "No Space Left" Fix

CodexFuse Team · 2026-11-04T09:22:29.778Z · 12 min read min read

Check disk space on Ubuntu the server way: df -h for the overview, du for what is eating the disk, find and ncdu to hunt large files, and the inode trap behind "No space left on device".

If you run an Ubuntu server, learning how to check disk space on Ubuntu is not optional maintenance — it is survival. Disks fill up silently: logs grow, package caches pile up, Docker images accumulate, and one morning your site throws errors because the filesystem hit 100%. The good news is that Ubuntu ships with two small, precise tools that answer every disk-space question: df (how full is each filesystem) and du (which folders are eating the space). This guide teaches both, plus the interactive ncdu browser and the workflow that fixes the dreaded "No space left on device" error — whether you are on VPS hosting or your own hardware.

How Do I Check Disk Space on Ubuntu?

Run df -h for the overview, then du to find what is eating the disk. That two-command habit covers 90% of disk-space work on Ubuntu. When a server actually reports an error, the full workflow is:

  1. df -h — see which filesystem is full (or nearly full).
  2. df -i — rule out the hidden trap: exhausted inodes.
  3. du -xh --max-depth=1 /mount | sort -rh | head — find the biggest directories on that filesystem.
  4. find /mount -xdev -type f -size +500M — list the biggest individual files.
  5. sudo ncdu /mount — browse the space interactively and delete safely.

The rest of this guide explains each step so you understand what you are looking at, not just which keys to press.

The df Command on Ubuntu: Your Disk Space Overview

df (disk free) reports how much space is total, used, and available on every mounted filesystem. The df command Ubuntu ships comes from GNU coreutils, so these flags behave the same on Debian, Fedora, and other GNU/Linux distributions. Run it with -h for human-readable sizes (K, M, G) instead of raw 1-kilobyte blocks, which is the default unit. Here is real output from a live Ubuntu machine:

Filesystem      Size  Used Avail Use% Mounted on
overlay         7.5G  243M  7.3G   4% /
/dev/mapper/rv  150G   82G   68G  55% /home/hatch

Read it left to right: the filesystem name, its total Size, how much is Used, how much remains in Avail, the Use%, and where it is Mounted on. Note the column is Avail, not "Available" — scripts and monitoring checks should match on that exact header. Avail is the space you can actually write to; on some filesystems a portion is reserved and never shows up here.

On a real server, plain df -h also lists tmpfs, devtmpfs, and other pseudo-filesystems that are not real disks and just add noise. Filter them out:

df -h -x tmpfs -x devtmpfs

The df command's most useful options, all verified against the GNU Coreutils documentation:

FlagWhat it showsWhen to use it
-hSizes in K, M, G (powers of 1024)Everyday checks — the default way to read df
-HSizes in powers of 1000Matching what disk manufacturers print on the box
-TAdds the filesystem type column (ext4, xfs, btrfs…)Deciding which cleanup tools apply to a filesystem
-iInode counts instead of block usageThe "disk full with free space" mystery (see below)
-x TYPEExcludes filesystems of that typeHiding tmpfs noise: -x tmpfs -x devtmpfs
df -h /pathOnly the filesystem holding that path"Is /var/log on a full partition?"

The du Command on Linux: Find What Is Eating the Disk

du (disk usage) does the opposite job from df: once df tells you which filesystem is full, du tells you what is filling it by summing up the space under any directory. The du command Linux distributions ship is also part of GNU coreutils. To check disk space Linux-wide rather than one folder at a time, combine df for the filesystem view with du for the folder view — start broad and drill down. The single most-used form is:

sudo du -sh /var/log

The -s flag summarizes to one total instead of listing every subdirectory, and -h keeps it human-readable. Use sudo when permission-denied errors hide directories you need to see — system folders like /var/log are not readable by a normal user.

To rank the biggest directories one level down, the classic one-liner is:

sudo du -h --max-depth=1 /var | sort -rh | head

This prints each immediate subdirectory of /var with its size, sorted largest first, showing only the top rows. Repeat the drill on the winner (for example du -h --max-depth=1 /var/lib | sort -rh | head) until you reach the culprit. The du flags worth memorizing:

FlagWhat it doesWhen to use it
-s / --summarizeOne total per argument"How big is /home overall?"
-hHuman-readable sizesReading the output like a person
--max-depth=NLists only N levels deep (0 = total only)Drilling down without the full tree
-x / --one-file-systemStays on one filesystemKeeping du from wandering into other mounts
--apparent-sizeFile sizes as applications see themSparse files (VM images, database files) where disk usage differs

One subtlety from the du manual: by default du reports disk usage (the blocks actually allocated), not the apparent file size. For sparse files — virtual-machine images are the classic case — apparent size can be much larger than what the disk holds. Add --apparent-size when the numbers do not match what ls shows.

Hunt the Biggest Individual Files With find

When du points at a bloated directory, find lists the actual files responsible. To list every file over 500 MB on the root filesystem, staying on that filesystem only:

sudo find / -xdev -type f -size +500M -exec ls -lh {} \; 2>/dev/null | awk '{print $5, $9}' | sort -rh | head

The -xdev flag keeps find from crossing into other mounted filesystems, -type f selects files only, and -size +500M filters by size. Drop the 2>/dev/null redirect if you want to see which directories were skipped. Adjust the threshold — +100M for a thorough hunt, +1G for the whales.

Nine times out of ten, the offenders are logs: web server access and error logs, application logs, or rotated archives nobody cleaned up. If you run a web server, check its log directory first (see our Nginx beginner guide for where those logs live). Before deleting anything, confirm the file is not actively being written to — and never delete a log a running service has open without understanding the consequences.

ncdu Tutorial: The Interactive Disk Map

ncdu (NCurses Disk Usage) is the fastest way to explore disk usage on a server with no graphical desktop. It scans like du, then lets you navigate the results with the keyboard and delete files in place. Install it from Ubuntu's repositories:

sudo apt install ncdu

Then scan a filesystem the same way you would with du:

sudo ncdu /

Use the arrow keys (or j/k) to move, Enter to open a directory, and the left arrow to go back up. The keys that matter, verified against the ncdu manual:

KeyAction
n / sSort by name / by size
gToggle the percentage graph
eShow or hide hidden and excluded files
iInfo about the selected item
dDelete the selected file or directory (asks for confirmation)
qQuit

Add -x to keep the scan on a single filesystem, exactly like du's flag. The d key deletes with a confirmation prompt, which makes ncdu the safest deletion tool in this guide — but it is still a real delete, not a trash bin, so look twice at system directories before pressing it.

"No Space Left on Device" With Free Space? Check Your Inodes

If Linux reports "No space left on device" while df shows free gigabytes, the disk is not full — the inodes are exhausted. This is the classic Linux disk full error that stumps beginners, because most tutorials teach only the block view and never the inode view. Every file and directory consumes one inode, and filesystems have a fixed supply created at format time. Millions of tiny files (PHP session files, mail queues, cache fragments) can use up every inode while barely touching the data blocks.

df -i

This prints inode usage instead of block usage, with its own verified headers:

Filesystem     Inodes IUsed IFree IUse% Mounted on
tmpfs            992K   295  992K    1% /tmp

Watch the IUse% column. We confirmed this trap firsthand on 2026-11-04: on a tmpfs with 512 MB free and 0% of its blocks used, but 100% of its inodes consumed, creating a new file with touch failed with "No space left on device". The fix is to delete the swarm of small files — find the directory with the most entries (mail spools, session folders, and thumbnail caches are the usual suspects), clean it out, and the error clears even though df never showed a full disk.

Free Up Space Safely on an Ubuntu Server

Once you know what is eating the disk, reclaim it with the tools built for each culprit. Work through this list in order — each step targets a different kind of waste:

1. Shrink the system journal. systemd's journal can grow to gigabytes. Check it with journalctl --disk-usage, then vacuum it — keep the most recent 100 MB or the last two days:

sudo journalctl --vacuum-size=100M
sudo journalctl --vacuum-time=2days

Per the journalctl manual, vacuuming removes only archived journal files, so combine with --rotate first if usage barely drops — that forces the active journal to archive so it becomes eligible for removal.

2. Clean the package cache. Ubuntu keeps every downloaded .deb. apt autoremove removes automatically-installed packages nothing depends on anymore; apt autoclean removes only .deb files that can no longer be downloaded (superseded versions). Run both:

sudo apt autoremove -y
sudo apt autoclean

3. Prune Docker. Unused images, stopped containers, and build cache are silent disk killers on any Docker host. docker system prune removes unused containers, networks, images, and build cache — it never touches volumes by default, which is where your data lives. Skip the confirmation prompt with -f:

docker system prune -f

Add --volumes only if you are certain no needed data sits in anonymous volumes. New to containers? Read our Docker beginner guide first.

4. Audit /var/log manually. Compressed rotations (*.gz) are usually safe to delete; check du -sh /var/log before and after. If logs regrow within hours, the fix is log rotation policy, not repeated deleting.

One caution for small servers: if your disk is tight and you are thinking about adding a swap file, check your space first — a swap file lives on the disk itself. See our swap space guide for the full procedure.

Checking Disk Space With the Ubuntu Desktop GUI

On an Ubuntu desktop you can skip the terminal: the Disk Usage Analyzer (Baobab) draws your disk as an interactive ring chart, and the Disks utility shows per-partition totals. Install the analyzer with sudo apt install baobab if it is not present, then launch it from the applications menu. The GUI is a fine secondary view, but every technique in this guide works identically over SSH — which is where Ubuntu servers live.

Sources

Every command and flag in this guide was verified against its primary documentation on 2026-11-04: the df(1) and du(1) manual pages (man7.org), the GNU Coreutils df documentation (gnu.org), the ncdu project site (dev.yorhel.nl/ncdu) and the ncdu(1) manual page (die.net), the journalctl manual page (manpages.debian.org), the apt-get(8) manual page, and the official Docker documentation for docker system prune. The df -h and df -i outputs shown are from a live Ubuntu machine, and the inode-exhaustion behavior was confirmed with a firsthand test on 2026-11-04.

Frequently Asked Questions

What is the difference between df and du?

df reads each filesystem's own counters and shows total, used, and available space per mount point. du walks the directory tree and sums up the files it can see. Because they measure different things, their numbers can disagree — df is the authority on "is the filesystem full," while du is the tool for "which folders are responsible."

Why does df say the disk is full when I cannot find any large files?

Check df -i first: if IUse% is at 100%, you are out of inodes, not bytes — millions of tiny files exhaust the inode supply while the data blocks stay nearly empty. The other classic cause is measurement difference: du only sums files it can see, while df reads the filesystem's own counters, so the two can disagree. When in doubt, trust df for "is it full" and use du plus find to hunt the cause.

How do I check disk space for one folder only?

Use du -sh /path/to/folder: -s gives a single total and -h makes it human-readable. To see which subfolders dominate, use du -h --max-depth=1 /path/to/folder | sort -rh | head for a ranked list.

Is it safe to delete files that ncdu shows?

ncdu's delete key asks for confirmation, but the deletion is permanent — there is no trash bin. Deleting in your home directory and obvious caches is low-risk; deleting in /bin, /lib, /etc, or /boot can break the system or prevent it from booting. When unsure, move the suspect files to a holding directory first and reboot before deleting them for good.

How often should I check disk space on a server?

Check manually whenever you deploy, and automate the rest: a df -h run in a daily cron job or your monitoring stack catches the slow fill before it becomes an outage. Alert at 80% used so you have time to investigate with du and ncdu rather than firefighting at 100%.

Featured on Twelve Tools Hunt for Tools Featured on LaunchBuff Launch Llama Tools Launch your MCP Top Web Development Companies in the US - OnToplist.com Designer Listings Listed on SeeWhatNewAI