Operations 4 min read

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.

Raymond Ops
Raymond Ops
Raymond Ops
Master Linux Disk Usage: Using df and du Commands Effectively

df command

Check disk space usage (cannot view size of a specific directory).

Command format:

df [option]
-h

human‑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:

<code>df -hT</code>
df output
df output

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>
df directory usage
df directory usage

Display inode information of filesystems:

<code>df -ih</code>
df inode output
df inode output

du command

Show the disk space occupied by files or directories.

Command format:

du [option] file/dir
-h

human‑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:

<code>du -hs</code>
du current directory
du current directory

Show the size of a specific directory or file:

<code>du -hs nodedemo/
du -hs nodedemo/Dockerfile</code>
du specific path
du specific path

Display the size of all files in the current directory:

<code>du -hs ./*</code>
du all files
du all files

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.

linuxCommand-lineSystem AdministrationDisk Usagedudf
Raymond Ops
Written by

Raymond Ops

Linux ops automation, cloud-native, Kubernetes, SRE, DevOps, Python, Golang and related tech discussions.

0 followers
Reader feedback

How this landed with the community

login 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.