Linux – How to get the summarized sizes of directories and their subdirectories

consolelinuxunix

Let's say I want to get the size of each directory of a Linux file system. When I use ls -la I don't really get the summarized size of the folders.

If I use df I get the size of each mounted file system but that also doesn't help me. And with du I get the size of each subdirectory and the summary of the whole file system.

But I want to have only the summarized size of each directory within the ROOT folder of the file system. Is there any command to achieve that?

Best Answer

This does what you're looking for:

du -sh /*

What this means:

  • -s to give only the total for each command line argument.
  • -h for human-readable suffixes like M for megabytes and G for gigabytes (optional).
  • /* simply expands to all directories (and files) in /.

    Note: dotfiles are not included; run shopt -s dotglob to include those too.

Also useful is sorting by size:

du -sh /* | sort -h

Here:

  • -h ensures that sort interprets the human-readable suffixes correctly.
Related Question