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

du -sh file_path

Explanation

  • 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
    

Just use the du command:

du -sh -- *

will give you the cumulative disk usage of all non-hidden directories, files etc in the current directory in human-readable format.

You can use the df command to know the free space in the filesystem containing the directory:

df -h .

du is your friend. If you just want to know the total size of a directory then jump into it and run:

du -hs

If you also would like to know which sub-folders take up how much disk space?! You could 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).