3

Is there a way to find the which directory or file is taking up the largest space on the Ubuntu Server?

I tried df -h

root@s-production:~# df -h
Filesystem      Size  Used Avail Use% Mounted on
udev            2.0G  4.0K  2.0G   1% /dev
tmpfs           396M  364K  395M   1% /run
/dev/vda1        40G  8.1G   30G  22% /
none            4.0K     0  4.0K   0% /sys/fs/cgroup
none            5.0M     0  5.0M   0% /run/lock
none            2.0G     0  2.0G   0% /run/shm
none            100M     0  100M   0% /run/user

2 Answers2

10

baobab

You can use baobab, which is a graphical tool, that displays the content with a list and a pie chart. You may need superuser privileges to see all directories and files. Do not run 'plain sudo', but use gksudo or sudo -H to avoid damaging your home directory.

sudo -H baobab
  • Select one of the partitions in the list

    enter image description here

  • Wait while baobab is searching

  • Look at the graphics to find where most of the drive space is used.

    enter image description here

Command line method

If you want to use or must use the command line, I would suggest the following method with an example corresponding to the same system as inspected with baobab.

Start looking at the root file system.

sudodus@xenial32 ~ $ sudo du -h --max-depth=1 / | sort -h
[sudo] password for sudodus: 
du: cannot access '/run/user/1002/gvfs': Permission denied
du: cannot access '/proc/13795/task/13795/fd/4': No such file or directory
du: cannot access '/proc/13795/task/13795/fdinfo/4': No such file or directory
du: cannot access '/proc/13795/fd/3': No such file or directory
du: cannot access '/proc/13795/fdinfo/3': No such file or directory
0       /proc
0       /sys
4,0K    /cdrom
4,0K    /lost+found
4,0K    /opt
4,0K    /snap
4,0K    /srv
88K     /tmp
172K    /mnt
272K    /root
340K    /dev
12M     /run
13M     /bin
14M     /sbin
16M     /etc
149M    /boot
601M    /var
673M    /lib
7,4G    /usr
23G     /home
709G    /media
740G    /
sudodus@xenial32 ~ $ 

Then look at the interesting directories, in this case the home directory.

sudodus@xenial32 ~ $ sudo du -h --max-depth=1 /home | sort -h
4,0K    /home/lost+found
60K     /home/lfs
18M     /home/alfons
52M     /home/milla
120M    /home/ingrid
313M    /home/pippi
2,6G    /home/shared
4,1G    /home/sudodus
16G     /home/findus
23G     /home

Next look at (for example) the 25 biggest subdirectories in the home dirctorory of findus,

sudodus@xenial32 ~ $ sudo du -h --max-depth=1 /home/findus | sort -h|tail -n25
35M     /home/findus/screenlet
41M     /home/findus/.Thunderbird-gammal
46M     /home/findus/linux-n-hardware
85M     /home/findus/.rpmdb
102M    /home/findus/.config
107M    /home/findus/.mozilla2
110M    /home/findus/.kde
116M    /home/findus/.mozilla1
117M    /home/findus/.mozilla4
216M    /home/findus/.mozilla
250M    /home/findus/.mozilla3
260M    /home/findus/.wine
317M    /home/findus/program
361M    /home/findus/.local
404M    /home/findus/.talsyntes
564M    /home/findus/.recoll
577M    /home/findus/.unison
687M    /home/findus/Dokument
758M    /home/findus/Musik
1,3G    /home/findus/.cache
1,7G    /home/findus/Skrivbord
1,8G    /home/findus/.linux
1,8G    /home/findus/utdelat
2,7G    /home/findus/.thunderbird
16G     /home/findus
sudodus@xenial32 ~ $ 
sudodus
  • 46,324
  • 5
  • 88
  • 152
4

try ncdu -x /. You can install it apt install ncdu

Carl
  • 724
  • 3
  • 5