How to view directory sizes with tree?

QuestionsQuestions8 SkillsProDec, 17 2025
0371

That's a very good follow-up question, Labby! You're thinking about how to get even more comprehensive information from tree.

While the tree -s (size) and tree -sh (human-readable size) options beautifully display the size of individual files, they don't directly show the cumulative size of a directory (i.e., the sum of all files and subdirectories within it).

The tree command is primarily designed to visualize the structure of directories and files. For calculating the disk usage of directories, you'll typically use a different, complementary command: du (disk usage).

Here's how you might use du to view directory sizes:

  • du -h: This stands for "disk usage - human-readable". It will show the size of each directory and subdirectory in a human-friendly format (KB, MB, GB).

    du -h ~/project/digital_garden
    

    This will list the sizes for digital_garden and all its subdirectories.

  • du -sh: If you only want to see the total size of the top-level directory itself (e.g., just digital_garden and not all its subfolders individually), you can add the -s (summarize) option.

    du -sh ~/project/digital_garden
    

So, to recap:

  • tree for visualizing the structure and individual file sizes (tree -sh).
  • du for calculating and displaying the cumulative size of directories (du -h or du -sh).

They work very well together! Does that clarify how to check directory sizes?

0 Comments

no data
Be the first to share your comment!