Storage problems hit fast on a Linux server. Apps fail, logs stop writing, and users see write errors. The terminal gives you everything needed to spot the issue before it spreads. A few commands tell you which partition is filling up, which folder caused it, and which file to clear out. Knowing how to linux check disk space saves hours of troubleshooting.
| Tool | What it shows | Best for |
|---|---|---|
| df | Free and used space on mounted filesystems | Partition-level overview |
| du | Space taken by files and folders | Tracking down heavy directories |
| ncdu | Interactive folder breakdown | Cleaning up live |
| lsblk | Block devices and partitions tree | Hardware-level layout |
The df Command to Check Disk Space on Mounted Partitions
The df command reports free and used space across mounted filesystems. Running it without arguments returns 1K blocks, which is awkward to read. Add the -h flag for human-friendly units like K, M, and G.
df -h
The output has six columns: filesystem name, total size, used space, available space, use percentage, and mount point. Anything above 85% in the use column deserves attention before write errors start.
Target a single mount by passing a path:
df -h /home
Add -T to print filesystem types like ext4, xfs, or btrfs. Use –total to print a grand total row across mounts. For inode usage instead of blocks, run df -i, since a server can run out of inodes long before it runs out of bytes.
The du Command for Directory and File Sizes
While df works at the partition level, du measures specific files and folders. Its default output lists every subdirectory on its own line, which buries the useful numbers. Pair -s for a summary with -h for readable sizes.
du -sh /var/log
That returns one line with the total size of /var/log. To go one level deep, use –max-depth:
du -h --max-depth=1 /var
This prints the size of every direct subdirectory inside /var, letting you walk down the tree until the heavy folders show up. The du reference page documents every option, from –apparent-size to –exclude. On busy servers, append 2>/dev/null to silence permission errors that clutter the output.
Using ncdu to Linux Check Disk Space Interactively
ncdu is a terminal-based scanner that runs as a sortable, navigable list. Install it with sudo apt install ncdu on Debian-based systems or sudo yum install ncdu on Red Hat. Then point it at any path:
ncdu /var
It builds a sorted view of folders by size. Arrow keys move you through the tree, and pressing d removes files without leaving the interface. For finding what is eating gigabytes on a crowded disk, ncdu is one of the fastest options around.
Other Useful Tools to Linux Check Disk Space
pydf for Color-Coded Partition Views
pydf is a Python rewrite of df with colored output. Install it through your package manager and run pydf with no flags. The same data shows up, but partitions near capacity stand out in red, which makes scanning multiple mounts faster.
lsblk for Physical Disk Layout
lsblk prints a tree of every block device on the system, from physical drives down to partitions and logical volumes. The output includes mount points, giving hardware context that df alone will not show. Helpful when an unmounted disk is the missing piece.
stat for Single-File Inspection
When you need every detail on one file, run stat filename. The stat system call returns byte size, block allocation, permissions, owner, and the three timestamps. Useful when checking suspiciously large files flagged by du.
lsof for Phantom Space
Sometimes df reports more usage than du can find. The cause is almost always a deleted file still held open by a running process. Run lsof +L1 to list those files, then restart or kill the holding process to release the blocks.
Combining Commands to Linux Check Disk Space Effectively
Piping commands together gives you targeted answers. To list the ten biggest folders inside /var:
du -h /var | sort -rh | head -n 10
The -rh flags sort in reverse and respect human-readable sizes. To exclude a file type from the total:
du -sh --exclude='*.zip' /home/user
The find command pulls files past a size threshold:
find /var/log -type f -size +100M
That returns every regular file in /var/log over 100 MB. Pipe it through xargs ls -lh for full listings. Add -mtime +30 to limit results to files older than thirty days, which is handy for clearing stale archives. For richer system-level monitoring across CPU, memory, and disk together, the dstat utility reports everything in one stream.
FAQs
When should I use df vs du?
df gives a partition-level view of free and used space across mounted filesystems. du measures the space inside specific folders or files. Use df for a quick health check and du to track down what is consuming the space.
Why does df report more space used than du shows?
Running processes can hold deleted files open, keeping their blocks reserved on disk. Run lsof +L1 to list them. Restarting or killing the process holding the handle releases the space immediately.
How do I find the largest files on Linux?
Run find / -type f -size +1G for files over a gigabyte, or pipe du -ah / | sort -rh | head -20 for the top twenty by size. ncdu handles this interactively for any chosen path.
Which directories fill up first on a Linux server?
/var/log holds system and application logs that grow daily. /tmp and /var/tmp collect short-lived files. /home stores user data, and /var/lib often hides large database files that consume entire partitions.
How can I clear a log file without deleting it?
Run > /var/log/syslog to truncate it to zero bytes while keeping the file handle open, so the running process keeps writing. The logrotate scheduler automates this rotation, compression, and cleanup.