Linux: Show Directory Size: du

By Xah Lee. Date: . Last updated: .

To show size of a directory, use du command.

Find the Size of a Dir

# show dir size of current dir
du --si -s .
Human readable format in metric unit. For example, M means megabyte (1000^2), not mebibyte (1024^2)
Means sum.

Find Size of All Top-Level Subdirs

# show size of current dir, human readable, 1st level dirs, sort by size.
du --si -d1 | sort -h
# show size of current dir, 1st level dirs, sort by size.
du -d1 | sort -n

Most Important Options

“sum”. Do not calculate size directory content.
-d n
Calculate all size of subdirs to depth n. -d 1 would be all the first level subdirs.

Human readable forms. (kilo, mega, giga)

Human readable form; in binary units.
Human readable form; in metric units.

Specify your own units:

Kibi bytes. (kibi = 2^10 = 1024) (default)
Mibi bytes. (mibi = 2^20 = 1048576)
-B 1000
Kilo bytes.
-B 1000000
Mega bytes.

When using “sort”, use -n to sort by number, use -h to sort human readable form of number.

Linux Shell Basics

Sys Admin


Linux Desktop