36

Is there an Ubuntu 14.04 terminal command to list the folder size and give a break down of every file size in the folder and its size?

One of my folders is taking a great deal of space, and I'd like to identify which file(s) or subfolders are the culprit.

I know du -sh gives the total folder size and ls -lah in each folder gives me files/sub-folder sizes, but is there a way to get an overall snap shot of everything?

4 Answers 4

9

Yes, there is the tree command. Install it via sudo apt-get install tree, and type the following:

tree -h

From man tree:

-h    Print  the size of each file but in a more human readable way, e.g. appending a size letter for kilo‐
      bytes (K), megabytes (M), gigabytes (G), terabytes (T), petabytes (P) and exabytes (E).

Done :)

2
  • Thanks this works great. Is there a way to show the total size within tree? I see the folder/file size it lists out but on the bottom report of total directors and files it scanned, is there a way to also list the size? (e.g., 96 directories, 307 files total size) Jan 27, 2015 at 7:12
  • 2
    you are welcome. yes there is. add --du option like tree -h --du. Jan 27, 2015 at 7:15
71

I like to use simply:

du -chd 1 | sort -h

It outputs the total size of each sub-directory from the current directory location (the "1" above), as well as a total of all sub-directories, and sorts it by human-readable sizes:

See how it looks here.

0
7

I found these helpful top 10 disk usages. For quick use, the command line is the following:

du -m | sort -nr | head -10

It lists all folders (including repetitive sub-folders) with most disk space usage sorted.

5

Tree is nice, and I know that might be what you asked for. I wanted to present you with something slightly different though to help you find what you are looking for (what is consuming the most space):

du -lah|grep -v -e '^.*K[[:space:]]'|sort -r -n

You can also pipe to head to just get the top list:

du -lah|grep -v -e '^.*K[[:space:]]'|sort -r -n|head

I was trying to actually give this with grep -v -e..., but it doesn't seem to be working on the output for du -lah for some reason. It should be sufficient though.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .