How to Quickly Identify Disk Space Hogs on Linux Servers
This guide shows step‑by‑step Linux commands—df, du, find, lsof, and tune2fs—to pinpoint large directories, uncover hidden space used by deleted files, and adjust reserved root space, helping you resolve mysterious disk‑space alerts efficiently.
How to Find Large Directories or Files
When a server triggers a disk‑space alarm, start by checking the filesystem with
df -Hlto confirm the reported usage.
To locate the offending directories, a straightforward approach is to run
du -hsin the root directory and then repeat the command in sub‑directories.
A more efficient method uses
duwith the
-dor
--max-depthoption together with
grepto filter and sort results, allowing you to quickly spot directories that occupy gigabytes or terabytes.
Alternatively, the
findcommand can directly search for large files, e.g.:
<code>find / -type f -size +1G -exec du -h {} \;</code>In practice,
findis often faster and more flexible than
du.
Sometimes the sum of sizes reported by
dudoes not match
dfbecause deleted files are still held open. Use
lsof +L1to list such files; restarting the related service (e.g., Tomcat) releases the space.
<code>lsof +L1</code>Linux also reserves a percentage of disk space for the root user (default 5%). This reservation can be changed with
tune2fs -m 1 /dev/vda1, which reduces the reserved space to 1% and frees up the previously hidden capacity.
<code>tune2fs -m 1 /dev/vda1</code>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.