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 -Hl to confirm the reported usage.
To locate the offending directories, a straightforward approach is to run du -hs in the root directory and then repeat the command in sub‑directories.
A more efficient method uses du with the -d or --max-depth option together with grep to filter and sort results, allowing you to quickly spot directories that occupy gigabytes or terabytes.
Alternatively, the find command can directly search for large files, e.g.: find / -type f -size +1G -exec du -h {} \; In practice, find is often faster and more flexible than du.
Sometimes the sum of sizes reported by du does not match df because deleted files are still held open. Use lsof +L1 to list such files; restarting the related service (e.g., Tomcat) releases the space. lsof +L1 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.
tune2fs -m 1 /dev/vda1Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
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.
