我昨天将旧服务器从 13.10 升级到 14.04 -> 14.10 -> 15.10。今天我发现磁盘空间已使用 100%,但我无法追踪使用情况。
当我运行时,du -h --max-depth=1 /
我收到以下日志,它似乎表明根路径已满,但我无法分辨来源是什么。
du: cannot read directory ‘/proc/4390/task/4390/ns’: Permission denied
du: cannot read directory ‘/proc/4390/fd’: Permission denied
du: cannot read directory ‘/proc/4390/map_files’: Permission denied
du: cannot read directory ‘/proc/4390/fdinfo’: Permission denied
du: cannot read directory ‘/proc/4390/ns’: Permission denied
du: cannot read directory ‘/proc/4392/task/4392/fd’: Permission denied
du: cannot read directory ‘/proc/4392/task/4392/fdinfo’: Permission denied
du: cannot read directory ‘/proc/4392/task/4392/ns’: Permission denied
du: cannot read directory ‘/proc/4392/fd’: Permission denied
du: cannot read directory ‘/proc/4392/map_files’: Permission denied
du: cannot read directory ‘/proc/4392/fdinfo’: Permission denied
du: cannot read directory ‘/proc/4392/ns’: Permission denied
du: cannot access ‘/proc/4393/task/4393/fd/3’: No such file or directory
du: cannot access ‘/proc/4393/task/4393/fdinfo/3’: No such file or directory
du: cannot access ‘/proc/4393/fd/4’: No such file or directory
du: cannot access ‘/proc/4393/fdinfo/4’: No such file or directory
0 /proc
du: cannot read directory ‘/sys/kernel/debug’: Permission denied
0 /sys
4.0K /mnt
1.5G /usr
du: cannot read directory ‘/root’: Permission denied
4.0K /root
4.0K /srv
104M /home
7.6M /sbin
12M /bin
47M /boot
du: cannot read directory ‘/var/lib/snmp/mib_indexes’: Permission denied
du: cannot read directory ‘/var/lib/php5’: Permission denied
du: cannot read directory ‘/var/lib/mysql’: Permission denied
du: cannot read directory ‘/var/lib/sudo’: Permission denied
du: cannot read directory ‘/var/lib/nginx/proxy’: Permission denied
du: cannot read directory ‘/var/lib/nginx/uwsgi’: Permission denied
du: cannot read directory ‘/var/lib/nginx/scgi’: Permission denied
du: cannot read directory ‘/var/lib/nginx/body’: Permission denied
du: cannot read directory ‘/var/lib/nginx/fastcgi’: Permission denied
du: cannot read directory ‘/var/log/unattended-upgrades’: Permission denied
du: cannot read directory ‘/var/log/mysql’: Permission denied
du: cannot read directory ‘/var/log/nginx’: Permission denied
du: cannot read directory ‘/var/spool/rsyslog’: Permission denied
du: cannot read directory ‘/var/spool/cron/atspool’: Permission denied
du: cannot read directory ‘/var/spool/cron/crontabs’: Permission denied
du: cannot read directory ‘/var/spool/cron/atjobs’: Permission denied
du: cannot read directory ‘/var/cache/ldconfig’: Permission denied
du: cannot read directory ‘/var/cache/nginx’: Permission denied
18G /var
8.0K /media
4.0K /lib64
du: cannot read directory ‘/run/log/journal/41cc217bd9afc046de32243850804999’: Permission denied
du: cannot read directory ‘/run/systemd/inaccessible’: Permission denied
1.5M /run
359M /lib
0 /dev
4.0K /opt
20G /
当我ls -la
在/我看到这个:
total 100
drwxr-xr-x 22 root root 4096 Jul 16 00:21 .
drwxr-xr-x 22 root root 4096 Jul 16 00:21 ..
drwxr-xr-x 2 root root 4096 Jul 16 00:16 bin
drwxr-xr-x 3 root root 4096 Jul 16 00:21 boot
drwxr-xr-x 13 root root 13680 Jul 16 18:46 dev
drwxr-xr-x 108 root root 12288 Jul 16 00:23 etc
drwxr-xr-x 3 root root 4096 Jul 15 23:23 home
lrwxrwxrwx 1 root root 32 Jul 16 00:18 initrd.img -> boot/initrd.img-4.2.0-42-generic
drwxr-xr-x 21 root root 4096 Jul 16 00:16 lib
drwxr-xr-x 2 root root 4096 Jul 16 00:14 lib64
drwx------ 2 root root 16384 Oct 18 2012 lost+found
drwxr-xr-x 3 root root 4096 Jul 15 23:21 media
drwxr-xr-x 2 root root 4096 Oct 9 2012 mnt
drwxr-xr-x 2 root root 4096 Oct 17 2012 opt
dr-xr-xr-x 169 root root 0 Jul 16 18:46 proc
drwx------ 5 root root 4096 Jul 15 23:21 root
drwxr-xr-x 19 root root 740 Jul 16 18:49 run
drwxr-xr-x 2 root root 12288 Jul 16 00:16 sbin
drwxr-xr-x 2 root root 4096 Oct 17 2012 srv
dr-xr-xr-x 13 root root 0 Jul 16 18:57 sys
drwxrwxrwt 7 root root 4096 Jul 16 19:04 tmp
drwxr-xr-x 10 root root 4096 Jul 15 23:23 usr
drwxr-xr-x 14 root root 4096 Jul 16 00:17 var
lrwxrwxrwx 1 root root 29 Jul 16 00:18 vmlinuz -> boot/vmlinuz-4.2.0-42-generic
再次,看不到正在使用磁盘空间的内容。
我应该在这里执行哪些步骤?
答案1
运行以下命令查找可用磁盘空间信息:
df -h
然后运行以下命令查找磁盘利用率信息:
sudo du -shc /
(注意须藤,这应该可以解决您看到的权限问题)
当您发现某个目录占用了大量磁盘空间时,cd
请转到该目录并重复步骤 2。不断重复此步骤,直到确定磁盘空间问题的根源。
答案2
如果我在 serverfault 上有足够的声誉,我会对@Paul Calabro 的回答发表评论。
我也意识到 OP 很高兴他们的问题得到了解决,但我认为这对那些更紧张或处于新手水平的人很有用。
会
sudo du -shc /*
难道不是一个更好的选择,因为它会列出根目录下的每个文件夹?
然而正如@Paul 后来提到的那样,cd
也许
cd /
# position 1
sudo du -shc *
cd <into whatever folder you want drill down into>
# repeat from position 1
我原本在想,du -x
但当这不起作用时,我意识到这是因为du -x *
没有删除home
文件夹,因为虽然它是确实,在不同的文件系统中,该文件夹*
会扩展以home
明确包含。
du -h
进一步使输出稍微更容易辨别大与不太大替换du -BM
,或更粗略地查看du -BG
,因为然后你会得到类似的报告
0M /sys
0M /mnt
1500M /usr
0M /root
0M /srv
104M /home
8M /sbin
12M /bin
47M /boot
18000M /var
0M /media
0M /lib64
2M /run
359M /lib
现在/var
文件夹明显突出,因为你不必注意单位是 K、M 还是 G。我意识到原来的没有-h
或-BM
也会突出显示大小,但这可能是细节太多或信息过载的情况。你真的在意一个文件夹在 20G 设备上使用 4 个块还是 400 个块吗?
在写这篇文章的时候,我觉得很遗憾没有一个-B%
选项可以将每一行报告为总数的百分比。
最后,稍微放松一下……
吹牛的权利
sudo du -scBP /
极度吹牛的权利
sudo du -scBE /