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) -k display sizes in kilobytes -m display sizes in megabytes -a list all filesystems, including those with size 0 -i show inode information -T display filesystem type
View system partition usage and filesystem type:
df -hTThis command shows each partition’s total, used, and available space.
Check the disk usage of the partition containing a specific directory:
df -h nodedemo/Display inode information of filesystems:
df -ihdu command
Show the disk space occupied by files or directories.
Command format:
du [option] file/dir -hhuman‑readable output (e.g., 10K, 10M, 10G) -s display only the total size of each argument (default unit kB)
Display the size of the current directory:
du -hsShow the size of a specific directory or file:
du -hs nodedemo/
du -hs nodedemo/DockerfileDisplay the size of all files in the current directory:
du -hs ./*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 du without options will recursively list every file, producing overwhelming output.
Signed-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.
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.
