Master Linux Disk Usage: How to Use df and du Commands Effectively
This guide explains how to use the Linux df and du commands to check overall disk space, view partition types, inspect inode information, and determine the size of specific files or directories, with examples and options for human‑readable output.
df command
Check disk space usage (cannot view the size of a specific directory). The basic syntax is df [option].
-h Output in a human‑readable format (e.g., 10K, 10M, 10G).
-k Output in kilobytes.
-m Output in megabytes.
-a List all filesystems, including those with size 0.
-i Show inode information.
-T Display the filesystem type of each partition.
Example: view partition usage and filesystem type:
df -hTThe command shows each partition's total, used, and available capacity.
To view the disk usage of the partition containing a specific directory:
df -h nodedemo/To output inode information of the filesystem:
df -ihdu command
Display the disk space occupied by files or directories. Syntax: du [option] file/directory.
-h Human‑readable output (e.g., 10K, 10M).
-s Show only the total size of the specified file or directory (default unit is K).
Show the size of the current directory:
du -hsShow the size of a specific directory or file:
du -hs nodedemo/ du -hs nodedemo/DockerfileShow the size of all files in the current directory:
du -hs ./*Note the difference between the following usages:
du -hs xxxx # Shows total size of the directory without listing each file du -hs xxxx/* # Lists size of each file and subdirectory under xxxxWarning: Do not run du indiscriminately on large directories, as it will traverse and list every file, potentially overwhelming the 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.
MaGe Linux Operations
Founded in 2009, MaGe Education is a top Chinese high‑end IT training brand. Its graduates earn 12K+ RMB salaries, and the school has trained tens of thousands of students. It offers high‑pay courses in Linux cloud operations, Python full‑stack, automation, data analysis, AI, and Go high‑concurrency architecture. Thanks to quality courses and a solid reputation, it has talent partnerships with numerous internet firms.
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.
