如何找到(按分组)占用所有磁盘空间的目录?
# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/vda1 60G 54G 6.4G 90% /
devtmpfs 1.4G 0 1.4G 0% /dev
tmpfs 1.4G 0 1.4G 0% /dev/shm
tmpfs 1.4G 161M 1.3G 12% /run
tmpfs 1.4G 0 1.4G 0% /sys/fs/cgroup
tmpfs 285M 0 285M 0% /run/user/0
看到 /dev/vda1 为 90% 没有帮助,如何检查哪些目录具有最大的磁盘储备?
例子:
/var/log/httpd 20GB
/var/log/pluto 10GB
/var/log/syslog 5GB
/var/log/tcpdump 1GB
/... restGB
答案1
除了上述情况之外,open(2)
写入的文件也会占用磁盘空间。我过去常常bigopenfiles
看到它们。
alias bigopenfiles='sudo lsof / | awk '\''{if($7 > 1048576) print $7/1048576 "MB" " " $9 }'\'' | sort -n -u'
其他“不可见”的文件是那些被程序open(2) O_TMPFILE
选择或已经打开和unlink(2)
编辑的文件。
alias deletedfiles='sudo lsof / | egrep '\''PID|\(deleted\)'\'''
例如,
walt@bat:~(0)$ bigopenfiles
lsof: WARNING: can't stat() fuse.gvfsd-fuse file system /run/user/1000/gvfs
Output information may be incomplete.
0MB NAME
1.03851MB /lib/x86_64-linux-gnu/libm-2.23.so
1.05076MB /usr/lib/firefox/browser/features/[email protected]
1.06348MB /lib/x86_64-linux-gnu/libglib-2.0.so.0.4800.2
1.07173MB /usr/lib/x86_64-linux-gnu/libcairo.so.2.11400.6
1.07496MB /usr/lib/x86_64-linux-gnu/libexempi.so.3.2.4
1.08072MB /usr/lib/x86_64-linux-gnu/libunistring.so.0.1.2
1.0952MB /usr/lib/evolution/libevolution-calendar.so.0.0.0
1.10789MB /usr/lib/x86_64-linux-gnu/libcamel-1.2.so.54.0.0
1.11092MB /usr/lib/x86_64-linux-gnu/indicator-datetime/indicator-datetime-service
1.11611MB /usr/lib/x86_64-linux-gnu/libprotobuf.so.9.0.1
1.12474MB /usr/sbin/ModemManager
...
walt@bat:~(0)$ deletedfiles
lsof: WARNING: can't stat() fuse.gvfsd-fuse file system /run/user/1000/gvfs
Output information may be incomplete.
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
mysqld 2233 mysql 4u REG 8,5 0 651554 /tmp/ibjp8exA (deleted)
mysqld 2233 mysql 5u REG 8,5 0 651560 /tmp/ibaGTQ9E (deleted)
mysqld 2233 mysql 6u REG 8,5 0 651561 /tmp/ibzy9sMJ (deleted)
mysqld 2233 mysql 7u REG 8,5 0 651575 /tmp/ibeDES4S (deleted)
mysqld 2233 mysql 11u REG 8,5 0 651710 /tmp/ibZSq7P0 (deleted)
dropbox 6614 walt 7u REG 8,5 0 651721 /tmp/#651721 (deleted)
gnome-ter 7035 walt 18u REG 8,5 65536 655802 /tmp/#655802 (deleted)