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
is 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 of subdirectories.-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.
If you have a question, put $5 at patreon and message me.