Linux 文件系统 Inode 耗尽问题解决

线上发现服务器执行任何命令都出现这个错误:

1
bash: cannot create temp file for here-document: No space left on device

发现磁盘空间是够的:

1
2
3
4
5
df -h
Filesystem      Size  Used Avail Use% Mounted on 
tmpfs           618M  8.8M  609M   2% /run
/dev/sda1       100G  50G    50G   1% /
...

查看 inode 用量:

1
2
3
4
Filesystem       Inodes   IUsed    IFree IUse% Mounted on
tmpfs            459110     842   458268    1% /run
/dev/sda1       2621440  2621440       0    0% /
...

根据这个帖子的方法,检查哪个目录下的文件多:

1
sudo find . -xdev -type f | cut -d "/" -f 2 | sort | uniq -c | sort -n

或者按照这个方法 count_em.sh

1
2
3
4
5
6
7
#!/bin/bash

# count_em - count files in all subdirectories under current directory.
echo 'echo $(ls -a "$1" | wc -l) $1' >/tmp/count_em_$$
chmod 700 /tmp/count_em_$$
find . -mount -type d -print0 | xargs -0 -n1 /tmp/count_em_$$ | sort -n
rm -f /tmp/count_em_$$

版权

评论