Check Disk Space and Usage in Linux
This guide explains how to check disk space and storage usage on a Linux system (VPS, dedicated server, cloud instance). A full disk can degrade performance, cause services to fail, or prevent logins. Knowing how to use df, du, and find helps you monitor partitions, identify the heaviest directories and files, and avoid outages.
Prerequisites
- SSH access to your Linux server (Debian, Ubuntu, or other distribution)
- Administrative rights (sudo) to read all directories (some are protected)
Connect to the Server
Connect via SSH to your server:
ssh user@server_ip_address
Useful Commands for Disk Space
Linux provides command-line tools to track used storage, free space, and which files or directories use the most space.
Command Overview
| Command | Description | Typical use |
|---|---|---|
df | Shows used and available space on mounted filesystems | Overview of partitions |
du | Estimates space used by directories and files | Identify heaviest directories |
find | Searches for files by size, name, type, or date | Find large or old files |
Check Disk Space with df
The df (disk free) command gives a quick view of disk space on all mounted filesystems. Use it to spot partitions that are filling up.
Syntax of df
df [OPTION]... [FILE]...
- OPTION: command options (human-readable format, filesystem type, inodes, etc.)
- FILE: optional file or directory. If omitted,
dfshows all mounted filesystems.
Common df Options
| Option | Description |
|---|---|
-h, --human-readable | Show sizes in human-readable units (K, M, G) |
-B, --block-size=SIZE | Use given block size (e.g. -BM for megabytes) |
-i, --inodes | Show inode usage instead of blocks |
-l, --local | Limit output to local filesystems |
--total | Show a total line |
-t, --type=TYPE | Limit to a filesystem type (e.g. ext4, xfs) |
-x, --exclude-type=TYPE | Exclude a filesystem type (e.g. tmpfs) |
-T | Show filesystem type in a column |
Examples: df Command
Show disk space for all filesystems (human-readable):
df -h
Example output:
Filesystem Size Used Avail Use% Mounted on
...
/dev/sda2 150G 12G 132G 9% /
/dev/sda1 260M 7.1M 253M 3% /boot/efi
tmpfs 768M 4.0K 768M 1% /run/user/1000
/dev/sdb1 40G 1.1G 37G 3% /mnt
Useful columns:
- Filesystem: device or filesystem name
- Size: total partition size
- Used: space in use
- Avail: free space
- Use%: usage percentage
- Mounted on: mount point
Check space for a specific mount point (e.g. /mnt):
df -h /mnt
Show only a given filesystem type (e.g. ext4):
df -h -t ext4
Exclude a filesystem type (e.g. tmpfs):
df -h -x tmpfs
Show filesystem type:
df -hT
Show inode usage:
Inodes store metadata for files and directories. If the disk has free space but inodes are exhausted, you cannot create new files.
df -i
Example output:
Filesystem Inodes IUsed IFree IUse% Mounted on
...
/dev/sda2 41611680 123735 41487945 1% /
/dev/sdb1 2621440 12 2621428 1% /mnt
- Inodes: total inodes
- IUsed: inodes in use
- IFree: free inodes
- IUse%: inode usage percentage
Check Disk Usage with du
The du (disk usage) command estimates space used by directories and files. Use it to see which directories or files use the most space.
Syntax of du
du [OPTION]... [FILE]...
- OPTION: command options
- FILE: directory or file to analyze. If omitted,
dustarts from the current directory.
Common du Options
| Option | Description |
|---|---|
-h, --human-readable | Sizes in human-readable units (K, M, G) |
-s, --summarize | Show only total for the given directory |
-a, --all | Include all files, not just directories |
-c, --total | Show a grand total at the end |
-d N, --max-depth=N | Limit traversal depth to N levels |
--exclude=PATTERN | Exclude files/directories matching pattern |
Examples: du Command
Total size of a directory (human-readable):
sudo du -sh /path/to/directory
Using sudo is recommended to access all directories (some are protected).
Include all files (including hidden):
sudo du -ah /path/to/directory
Exclude certain file types (e.g. .log files):
sudo du -ah --exclude='*.log' /path/to/directory
Size of first-level subdirectories (e.g. /var):
sudo du -h --max-depth=1 /var
Example output:
22M /var/log
97M /var/lib
4.0K /var/yp
216M /var
Sort subdirectories from largest to smallest:
sudo du -h --max-depth=1 /var | sort -rh
Example output:
216M /var
97M /var/lib
97M /var/cache
22M /var/log
...
Find Large Files with find
The find command searches for files by size, name, type, or date. Combined with du, it helps locate the largest files.
List files larger than 50 MB in a directory (e.g. /var):
sudo find /var -type f -size +50M -exec ls -lh {} \;
Example output:
-rw-r--r-- 1 root root 65M May 6 20:29 /var/lib/rpm/rpmdb.sqlite
Search for files larger than 100 MB system-wide:
sudo find / -type f -size +100M 2>/dev/null
The redirect 2>/dev/null hides permission denied errors to keep output readable.
Find files modified more than 30 days ago (for cleanup):
sudo find /var/log -type f -mtime +30
Command Summary
| Goal | Command |
|---|---|
| Partition overview | df -h |
| Space for a mount point | df -h /mnt |
| Inode usage | df -i |
| Directory size | sudo du -sh /path |
| Subdirectories sorted by size | sudo du -h --max-depth=1 /var | sort -rh |
| Files larger than 50 MB | sudo find /var -type f -size +50M -exec ls -lh {} \; |
Troubleshooting
Full or nearly full partition
- Use
duto find the heaviest directories (often/var,/tmp,/home, logs). - Clean old logs:
sudo journalctl --vacuum-time=7dor remove files in/var/log. - Clear package caches:
sudo apt clean(Debian/Ubuntu) or equivalent. - Remove temporary files in
/tmpif needed.
"No space left on device" but space appears free
- Check inodes:
df -i. If IUse% is 100%, the disk has no inodes left (many small files). Remove or move files to free inodes.
Commands fail due to permissions
- Use
sudoforduandfindon system directories (/var,/etc,/root, etc.).
References
- Man pages:
man df,man du,man find