提示"No space left on device"错误的解决方法

2025-11-20 02:34:04

1、系统:centos 7.4,磁盘空间8G,CPU 4核,内存4G(最好给大点,创建文件需要大内存)。

[root@appjzw ~]# mkdir /test

[root@appjzw ~]# echo /test/{1..6000000}.txt |xargs touch #创建的文件太多了,只能用这种方式创建。

2、[root@appjzw ~]# crontab -e/tmp/crontab.MApBTV: No space left on device 

[root@appjzw ~]# touch xmh.txttouch: cannot touch ‘xmh.txt’: No space left on device

3、查看磁盘空间

[root@appjzw ~]# df -h

Filesystem      Size  Used Avail Use% Mounted on

/dev/sda1       8.0G  3.2G  4.9G  39% /      ##可以发现磁盘容量是空闲很多的

devtmpfs        1.7G     0  1.7G   0% /dev

tmpfs           1.7G     0  1.7G   0% /dev/shm

tmpfs           1.7G  8.7M  1.7G   1% /run

tmpfs           1.7G     0  1.7G   0% /sys/fs/cgroup

tmpfs           332M     0  332M   0% /run/user/0

4、[root@appjzw ~]# df -i

Filesystem      Inodes   IUsed  IFree IUse% Mounted on

/dev/sda1      4193792 4193792      0  100% /       #但是inode空间已满了

devtmpfs        422466     395 422071    1% /dev

tmpfs           424923       1 424922    1% /dev/shm

tmpfs           424923     473 424450    1% /run

tmpfs           424923      16 424907    1% /sys/fs/cgroup

tmpfs           424923       1 424922    1% /run/user/0

5、解决办法


使用find命令查找大于10M的目录,可以从df -i看出是在 根 /下容量不足,那么我们就从 / 下开始排查。

[root@appjzw ~]# find / -type d  -size +10M |xargs  ls -lhd  #find查找

drwxr-xr-x. 2 root root 97M Feb 15 14:00 /test

[root@appjzw ~]# ls /test/ |wc -l  #对该目录文件数量统计

4168011

#定位好目录后删除小文件

[root@appjzw /]# rm -rf /test/*  #直接 rm -rf * 的话是删除不了大量的小文件

-bash: /usr/bin/rm: Argument list too long

[root@appjzw /]# cd /test/

[root@appjzw test]# ls |xargs rm -f#删除大量的小文件,使用该命令删除

[root@appjzw /]# ls /test/ |wc -l #小文件已经删除

声明:本网站引用、摘录或转载内容仅供网站访问者交流或参考,不代表本站立场,如存在版权或非法内容,请联系站长删除,联系邮箱:site.kefu@qq.com。
猜你喜欢