Linux: Show Directory Size: du
To show size of a directory, use du
command.
Find the Size of a Dir
# show dir size of current dir du --si -s .
--si
- Human readable format in metric unit. For example, M means megabyte (1000^2), not mebibyte (1024^2)
-s
- 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
-s
- “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)
-h
- Human readable form; in binary units.
--si
- Human readable form; in metric units.
Specify your own units:
-k
- Kibi bytes. (kibi = 2^10 = 1024) (default)
-m
- 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.