Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

My disk is running out of space:

$ df -h
Filesystem      Size  Used Avail Use% Mounted on
...
/dev/sda7       803G  715G   48G  95% /home

I'd like to go through the whole home directory and find out the top 10 space-consuming directories or files, to decide whom to be removed.

du -sh * can see size of all subdirectories, but it only gets current folder. I might need to divide into many subdirs respectively and recursively to get who are the culprits I need.

Is there a good way to do this?

share|improve this question

8 Answers 8

up vote 3 down vote accepted

If you can use a GUI try Baobab. This is a graphical tool for analyzing hard disk space usage.

share|improve this answer

Use this command:

t=$(df|awk 'NR!=1{sum+=$2}END{print sum}');du / –exclude /proc –exclude /sys –max-depth=1|sed '$d'|sort -rn -k1 | awk -v t=$t 'OFMT="%d" {M=64; for (a=0;a<$1;a++){if (a>c){c=a}}br=a/c;b=M*br;for(x=0;x<b;x++) {printf "\033[1;31m" "|" "\033[0m"}print " "$2" "(a/t*100)"% total"}'

It will show you the sort of a graph in command line showing the directories that consume the most of the space in percentage.

If you want to analyze the /home only - you can specify this in the command like this:

t=$(df|awk 'NR!=1{sum+=$2}END{print sum}');du /home –exclude /proc –exclude /sys –max-depth=1|sed '$d'|sort -rn -k1 | awk -v t=$t 'OFMT="%d" {M=64; for (a=0;a<$1;a++){if (a>c){c=a}}br=a/c;b=M*br;for(x=0;x<b;x++) {printf "\033[1;31m" "|" "\033[0m"}print " "$2" "(a/t*100)"% total"}'

It will look like that: enter image description here

Taken from here.

share|improve this answer

+1 for Baobab. on the command line, I usually just use du -hcsx * or du -hcsx * | sort -h (needs a failry recent version of sort) and then check subdirectories as I go on.

Also, mc has a neat feature of calculating subdirectory sizes by pressing Ctrl+Space on top of it (press Ctrl+Space on top of .. to make it calculate the size for all subdirectories. Then you can select sort by size in the menu.

share|improve this answer
2  
on the command line, you should try ncdu. It's an ncurses du, basically. –  Rob Jan 15 '13 at 16:35

du | sort -rn | head

  • du = Disk Usage
  • sort using numerical order, reverse
  • the ten first lines
share|improve this answer

ncdu is a command line option that scans directories and lists disk usage from highest to lowest. It's my go to tool for this.

You will still have to dive in recursively this way, but it's a nice easy way to do it.

share|improve this answer

Another GUI favorite: kdirstat

It has nice drilldown capabilities, and and (extensible) tools menu to help you delete/compress your files.

I also have a command line script that I call dir_usage that I've uploaded to pastebin.

share|improve this answer

find . -type f -print0 | xargs -0 du | sort -n | tail -10 | cut -f2 | xargs -I{} du -sh {}

share|improve this answer
3  
Can you expand upon your answer? –  50-3 Nov 19 '13 at 10:42

Try this:

du -a /dir | sort -nr | cut -f2 | xargs du -sh | head -n 10
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.