How do I check disk space on a Linux server?
Run df -h to see how full each file system is, then run du -h --max-depth=1 on the full one to find the folder that uses the space. df reads the file system itself and du adds up the files it can reach, so the two can disagree.
Last updated
Commands checked on Ubuntu 24.04.5 LTS (the ubuntu:24.04@sha256:562111b88caa79c71391c0c4d3c2114a7d5c35915c20561fd893cb1e07929e6b
container image), .
Run df -h and look at the Use% column. A file system near 100% is the one that is full. Then run du -h --max-depth=1 on its mount point, go into the biggest folder, and repeat until you see what is using the space.
See which file system is full
df reports on file systems, not on folders. With no argument it lists all of them. With a path it shows the file system that holds the path. This server has a small file system mounted at /dev/shm, 64 MB in size, so the examples point df at it:
$ df -h /dev/shm
Filesystem Size Used Avail Use% Mounted on
shm 64M 52M 12M 82% /dev/shm
Size is the whole file system, Used is what files occupy and Avail is what a normal user can still write. Use% is the part in use. On a real disk Used and Avail often add up to a little less than Size, because ext4 keeps some blocks for root by default. A server whose Use% passes 90% is worth a look. Nothing breaks at an exact number, but an application that writes a log or an upload on a full disk fails in odd ways.
-T adds the type of the file system, and -H switches from powers of 1024 to powers of 1000:
$ df -hT /dev/shm
Filesystem Type Size Used Avail Use% Mounted on
shm tmpfs 64M 52M 12M 82% /dev/shm
$ df -H /dev/shm
Filesystem Size Used Avail Use% Mounted on
shm 68M 55M 13M 82% /dev/shm
Both commands show the same disk. When you compare numbers from two tools, make sure both use the same unit.
Count the inodes too
A file system also has a fixed number of inodes, and every file or folder uses one, even an empty file. A disk can have free space and no free inodes. df -i shows them. This form picks the columns:
$ df --output=source,iused,ipcent /dev/shm
Filesystem IUsed IUse%
shm 2012 1%
Here the inodes are far from used up. When IUse% reaches 100%, new files fail with “No space left on device” while df -h still shows free space. The usual cause is an application that writes one small file per session, per message or per cache entry. To find the folder with the most files, count them per top level folder:
$ find /dev/shm/data -xdev -type f | cut -d/ -f1-5 | sort | uniq -c | sort -rn | head -3
2001 /dev/shm/data/cache
2 /dev/shm/data/logs
1 /dev/shm/data/uploads
The cache folder holds 2001 files. The 2000 sessions in it take no space at all, and that is why df -h showed nothing odd.
Find the folder that uses the space
du adds up the files under a path. -s prints one total, -h makes the numbers readable:
$ du -sh /dev/shm/data
52M /dev/shm/data
The total matches df. To see where it comes from, ask for one level and sort the lines by size. sort -h understands 4.0M and 30M:
$ du -h --max-depth=1 /dev/shm/data | sort -h
4.0M /dev/shm/data/tmp
6.0M /dev/shm/data/cache
12M /dev/shm/data/uploads
30M /dev/shm/data/logs
52M /dev/shm/data
The biggest folder is logs. Look inside the same way, or list the files by size:
$ ls -lhS --time-style=long-iso /dev/shm/data/logs
total 30M
-rw-r--r-- 1 dev dev 20M 2026-11-20 08:00 app.log
-rw-r--r-- 1 dev dev 10M 2026-11-20 08:00 app.log.1
One log of 20 MB and its rotated copy of 10 MB make up most of the disk. Searching a whole tree for the biggest files is the subject of the find large files article. Reading what is in such a log is in the logs article.
When you start du at /, add -x. It then stays on one file system and does not walk into /proc, /sys or a mounted network share.
What fills a server disk
The same places come up again and again:
- Logs under
/var/logthat nobody rotates, and the systemd journal. - Old releases of an application, and uploads from its users.
- Backups and database dumps written to the same disk as the data.
- Package caches under
/var/cache, and the images and volumes of a container runtime. - Core dumps from a program that crashes in a loop.
- Many small files: sessions, mail, cache entries. These fill inodes first.
When df and du disagree
df asks the file system how many blocks are in use. du walks the folders and adds what it finds. They differ for three reasons:
- A file was deleted while a program still had it open. The name is gone, so
dudoes not see it, but the blocks stay in use until the program lets go. This is the most common one, and the find large files article shows how to find it. ducould not read some folders. It prints “Permission denied” for them and leaves them out of the total. Run it withsudo, as in sudo for one command.- Files were written to a folder, and later a disk was mounted on that folder. The old files are still on the first disk, hidden under the mount.
Mistakes people make
You delete first and look later. Check what a command will remove before you run it; safe rm on servers shows how.
You look at df -h and never at df -i. A full inode table gives the same error as a full disk.
You remove a log that an application is still writing. The space does not come back, because the program keeps the file open. Truncate such a file instead, or restart the program.
You run du -sh /* and wait for minutes on a large server. Pick the file system from df first, then run du on that mount point with -x.
If you look after more than one server, open them as panes of one tab and start a broadcast in Commands mode. Valakes shows a card with one row per host and runs the command only on the hosts you leave checked, so df -h can go to all of them in one step. Guide: How do I run the same command on several servers at once, safely?
Questions
Why does df say the disk is full when du adds up to much less?
Usually a program still holds a file that someone deleted, and the space stays in use until the program closes it or stops. Less often, files sit under a folder that a later mount covers, or du could not read some folders. The find large files article shows how to see deleted files that are still open.
What does "No space left on device" mean when df -h shows free space?
Often the file system has run out of inodes. Every file uses one, however small. Run df -i and look at IUse%.
What is the difference between df -h and df -H?
-h divides by 1024 and prints sizes such as 64M. -H divides by 1000 and prints 68M for the same disk. The disk is the same; the unit is not.
References
- df(1) on Ubuntu 24.04, the options -h, -H, -i, -T and --output manpages.ubuntu.com
- du(1) on Ubuntu 24.04, the options -s, -h, -x and --max-depth manpages.ubuntu.com
- df(1) at man7.org, the options -h, -H, -i, -T and --output man7.org
- du(1) at man7.org, the options -s, -h, -x and --max-depth man7.org
Related articles
The app is free.
Get notified at launchmacOS is coming to the Mac App Store. iOS and Android later.