97

I like tree it's a nice way to display my files and the size of folders/directories. But the -h option only shows the size of the directory, not the cumulative size of its contents.

/media/
├── [ 16K]  64D9-E862
│   ├── [8.0K]  downloads

I know for a fact that my external drive has more that 16kB in it.

How can I fix that with tree 1.5? Better yet how do I upgrade to 1.6?

AncientSwordRage
  • 1,774
  • 1
  • 20
  • 27

4 Answers4

123

Only for tree 1.6 and above

You might want to look at:

man tree

--du For each directory report its size as the accumulation of sizes of all its files and sub-directories (and their files, and so on). The total amount of used space is also given in the final report (like the 'du -c' command.) This option requires tree to read the entire directory tree before emitting it, see BUGS AND NOTES below. Implies -s.

So you should use:

tree --du -h
Sheharyar
  • 453
squareborg
  • 2,495
  • 9
    This for pointing to --du in 1.6. I always use du -h --max-depth= 1 or 2 or maximum 3. Then drill down (cd) into where I want to go, and run the same command agin. When tree is used with -L it counts only directories/and files up to a given level. Comapred to du which calculates all files irrespective of --max-depth parameter, but just prints up to a specified level. It makes tree not helpful for me. Thanks though! – Tagar Jul 02 '15 at 04:20
  • 2
    I suggest adding the -a option to output locations which are hidden (start with a dot, e.g. .cache) – awatts Oct 03 '19 at 14:26
  • I'm so sad it reports 0 size when I add the -d option. I just want to see directory sizes and not file sizes with tree – Shayan Mar 12 '22 at 17:30
  • 4
    This works, however it does not work with limiting the amount of recursion that is used. for instance. If you use tree --du -h -L 2 this does not work. – Dave Oct 01 '22 at 15:15
21

Adding on the accepted answer... with any substantial number of folders, you are going to potentially get a huge output from that command.

If like me, you are wanting to identify some big folders to purge because you are filling up your drive, you might find it helpful to combine the tree command with a grep to limit it to folders that are Gigabytes in size, saving yourself the need to traipse through the whole output:

tree --du -h | grep G]

Jimmo
  • 311
2

This is an old thread but this might be helpful for others in the future.

tree --du -h /mnt/cache/ | grep ^├─

As discussed above using the limit flag -L means tree will not add up the size of files/directorys below the limit. So if we use grep and only show lines beginning with ├─ we are effectly doing a -L 1 but we get the full size.

We can then drill down to see where the space is being used by running the command again but modifying the directory in the direction of interest.

AdminBee
  • 22,803
-1

Please use this code might help you,

$ sudo tree -hF

or

# tree -hF
terdon
  • 242,166
king
  • 21