How do I get the size of a directory using the command line?

The du command (disc usage) command reports the sizes of directory trees inclusive of all their contents and the sizes of the individual files. It’s a useful command to track down directories consuming large or excessive amounts of space. Note, the sizes of directories and files it reports are approximations, not exact numbers.

The basic syntax is du -sh <directory> .

Linux du command
Linux du command

The -s  (for suppress or summarise) switch tells the du  command to report only the total disk space occupied by a directory tree and to suppress reports for sub-directories.

The -h  (human readable) option makes the output easier to read using K = kilobytes, M = megabytes and G = gigabytes.

The du -sh * command will give you the size of all the directories and files in the current directory. The df -h or df -h . command will display the free disk space.

Linux df command
Linux df command

You May Also Like