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:

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

df -h nodedemo/
df directory usage
df directory usage

Display inode information of filesystems:

df -ih
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:

du -hs
du current directory
du current directory

Show the size of a specific directory or file:

du -hs nodedemo/
du -hs nodedemo/Dockerfile
du specific path
du specific path

Display the size of all files in the current directory:

du -hs ./*
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.

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.

Linuxcommand-linedisk 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

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.