Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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
up vote 4 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

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

du | sort -rn | head

  • du = Disk Usage
  • sort using numerical order, reverse
  • the ten first lines
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
on the command line, you should try ncdu. It's an ncurses du, basically. – Rob Jan 15 '13 at 16:35

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

Try this:

du -a /dir | sort -nr | cut -f2 | xargs du -sh | head -n 10
share|improve this answer
find . -type f -print0 | xargs -0 du | sort -n | tail -10 | cut -f2 | xargs -I{} du -sh {}

The commandline above does the following (in order):

  • Find all files (not directories) within current folder
  • Display usage for each of them
  • Sort the results numerically
  • Use only the last 10 (highest usage) lines
  • Cut out the 10 filenames (first column is usage, second is filename)
  • Display usage for each filename (in human format)

This will result in a list of human-readable sizes of the largest 10 files within the current folder and subfolders.

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

You must log in to answer this question.

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