How to Quickly Identify Disk Space Hogs on Linux Servers
This guide explains how to use Linux commands such as df, du, find, and lsof to quickly locate directories, files, or deleted resources that are consuming disk space, and shows how to adjust reserved space with tune2fs to recover seemingly missing storage.
During server operations, disk space alerts are common. First, run
df -Hlto view current usage and verify the alert.
How to Find Large Directories or Files Consuming Disk Space?
A simple way is to start at the root directory and execute
du -hsto list the size of each top‑level directory, then drill down into the larger ones.
A more efficient method uses
duwith the
-dor
--max-depthoption to limit the depth of the search, and pipes the output to
grepto filter for entries measured in G or T, then sorts the results.
Alternatively, the
findcommand can locate large files directly:
<code>find / -type f -size +1G -exec du -h {} \;</code>In terms of performance,
findis generally faster and more flexible than
dufor this purpose.
These techniques help you quickly pinpoint the directories or files that are hogging disk space.
Why Is Disk Space Mysteriously Consumed?
Sometimes the total size reported by
dudoes not match the usage shown by
df. For example,
dfmay indicate 37 GB used, while summing
du -hsacross the filesystem yields only about 10 GB. This discrepancy often means that deleted files are still holding space because they remain open by a process.
You can reveal such orphaned files with
lsof +L1:
<code>lsof +L1</code>The output may show a large log file (e.g., ~28 GB) that has been deleted but not released. Restarting the associated service (e.g., Tomcat) frees the space.
Another common confusion arises when the sum of
Usedand
Availis less than
Size. Linux reserves a percentage of disk space (default 5 %) for the root user as a safety buffer, ensuring critical applications have room even when the disk appears full.
You can adjust this reserved space with
tune2fs -m 1 /dev/vda1to set the reservation to 1 %.
After reducing the reserved percentage, the previously “missing” space becomes available.
Efficient Ops
This public account is maintained by Xiaotianguo and friends, regularly publishing widely-read original technical articles. We focus on operations transformation and accompany you throughout your operations career, growing together happily.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.