Operations 4 min read

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.

MaGe Linux Operations
MaGe Linux Operations
MaGe Linux Operations
Master Linux Disk Usage: How to Use df and du Commands Effectively

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 -hT

The 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 -ih

du 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 -hs

Show the size of a specific directory or file:

du -hs nodedemo/
du -hs nodedemo/Dockerfile

Show 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 xxxx

Warning: Do not run du indiscriminately on large directories, as it will traverse and list every file, potentially overwhelming the output.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

Linuxdisk usagedudf
MaGe Linux Operations
Written by

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.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.