Ubuntu 上的磁盘使用情况 - 查找最大大小的目录或文件

Har*_*M V 1 disk disk-usage

有没有办法找到哪个目录或文件在 Ubuntu 服务器上占用了最大的空间?

我试过 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
Run Code Online (Sandbox Code Playgroud)

sud*_*dus 5

猴面包树

您可以使用baobab,这是一个图形工具,它显示带有列表和饼图的内容。您可能需要超级用户权限才能查看所有目录和文件。不要运行 'plain sudo',而是使用gksudosudo -H以避免损坏您的主目录。

sudo -H baobab
Run Code Online (Sandbox Code Playgroud)
  • 选择列表中的分区之一

    在此处输入图片说明

  • 等待baobab搜索中

  • 查看图形以找出大部分驱动器空间的使用位置。

    在此处输入图片说明

命令行方法

如果您想使用或必须使用命令行,我会建议使用以下方法,并以与使用baobab.

开始查看根文件系统。

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 ~ $ 
Run Code Online (Sandbox Code Playgroud)

然后查看有趣的目录,在本例中是主目录。

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
Run Code Online (Sandbox Code Playgroud)

接下来看(例如)主目录中最大的25个子目录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 ~ $ 
Run Code Online (Sandbox Code Playgroud)