How Do I Get The Size of a Directory In Command Line?

The most basic way to do this is use a command du. Here's how.

du -sh file_path


  • du (disc usage) command estimates file_path space usage
  • The options -sh are (from man du):

      -s, --summarize
             display only a total for each argument
      -h, --human-readable
             print sizes in human readable format (e.g., 1K 234M 2G)

    To check more than one directory and see the total, use du -sch:

      -c, --total
             produce a grand total

If you also would like to know which sub-folders take up how much disk space? You can extend this command to:

du -h --max-depth=1 | sort -hr

which will give you the size of all sub-folders (level 1). The output will be sorted (largest folder on top).

A Little "Trick"

To avoid entering a ton of arguments to get a decent output, you can just use ncdu which will give you an interactive readout of the entire directory and subdirectory.

That's about it for this article!

If you have any comments, feel free to post them below or find us on Twitter and Facebook!

-Until Next time

February 05 2020

Add or review comments

Please leave your comment

Existing comments

Comments 0