Master Linux Disk Usage: Using df and du Commands Effectively
This guide explains how to use the Linux df and du commands to inspect disk space, interpret their options such as -h, -k, -i, and -T, view partition usage, directory-specific usage, inode information, and avoid common pitfalls when measuring file sizes.
df command
Check disk space usage (cannot view size of a specific directory).
Command format:
df [option] -hhuman‑readable output (e.g., 10K, 10M, 10G)
-kdisplay sizes in kilobytes
-mdisplay sizes in megabytes
-alist all filesystems, including those with size 0
-ishow inode information
-Tdisplay filesystem type
View system partition usage and filesystem type:
<code>df -hT</code>This command shows each partition’s total, used, and available space.
Check the disk usage of the partition containing a specific directory:
<code>df -h nodedemo/</code>Display inode information of filesystems:
<code>df -ih</code>du command
Show the disk space occupied by files or directories.
Command format:
du [option] file/dir -hhuman‑readable output (e.g., 10K, 10M, 10G)
-sdisplay only the total size of each argument (default unit kB)
Display the size of the current directory:
<code>du -hs</code>Show the size of a specific directory or file:
<code>du -hs nodedemo/
du -hs nodedemo/Dockerfile</code>Display the size of all files in the current directory:
<code>du -hs ./*</code>Note the difference between
du -hs xxxx(shows total size of the directory) and
du -hs xxxx/*(lists size of each item inside).
Warning: Running
duwithout options will recursively list every file, producing overwhelming output.
Raymond Ops
Linux ops automation, cloud-native, Kubernetes, SRE, DevOps, Python, Golang and related tech discussions.
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.