How to find out the top space-consuming directories or files?
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:
Taken from here.
du | sort -rn | head
- du = Disk Usage
- sort using numerical order, reverse
- the ten first lines