What's the Fastest Way to Get Disk Usage Info?

January 18, 2026 1 answer
Asked by CuriousCoder42
I'm running a script that checks the used disk space every 10 seconds using the `df` command. While it's pretty quick, I wonder if there's a more efficient method that uses fewer resources. I know I could use `stat` as in the way I listed, and it's slightly faster, but I'm curious if there's an even better approach, perhaps by accessing something directly in the `/sys/` directory. I'm also aware that rewriting the whole script in a compiled language would be overkill. If anyone has suggestions for optimizing this in shell, I'd love to hear them!

Answers

DiskWhisperer93
Honestly, `df` is already highly optimized for what you're doing. There isn't a secret file in `/sys` that gives you filesystem usage without calling home base, which would hit the kernel anyway. The differences you're looking for are just tiny tweaks in performance!

KernelExplorer87: Totally right! If you run `sudo strace df /`, youโ€™ll see how it all connects. It's interesting to see how it pulls data from `/proc/self/mountinfo` along with the stats from `statfs`. You can really see the backend magic in action!

Reply to this answer

Add your answer

Answers are reviewed before publication.

Related Discussions