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?

8 Answers 8


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


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.


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.


du | sort -rn | head

  • du = Disk Usage
  • sort using numerical order, reverse
  • the ten first lines

+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.

  • 2
    on the command line, you should try ncdu. It's an ncurses du, basically.
    – Rob
    Jan 15, 2013 at 16:35

Try this:

du -a /dir | sort -nr | cut -f2 | xargs du -sh | head -n 10

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.

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.

  • 3
    Can you expand upon your answer?
    – 50-3
    Nov 19, 2013 at 10:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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