Get Total Directory Size via Command Line

Jul 15, 2022 17:00 · 125 words · 1 minute read

For that, we can use du, a command line tool to display disk usage statistics. du comes pre-installed on all Linux & macOS machines.

1
2
3
4
5
6
7
8
# Show the disk usage for every file in the current directory, incl. the directory itself in the last line.
# `-h` flag for "human-readable" output (= use unit suffixes like "K" & "M" for Megabyte, Kilobyte etc., 
# each unit based on the powers of 1024)
du -h

du -sh # Only show the disk usage for the current directory
du -s --si # Change human-readable output, so units based on the powers of 1000 are used. 
du -d 2 -h # Show the disk usage two directories deep

(via man du)