释放已删除空间资源
查看已删除文件
当遇到df 和du 看到的磁盘空间不一致的时候,大概率是因为文件句柄未释放的情况下,文件被删除;我们可以通过下面命令来查看:
lsof |grep deleted
这些就是已删除文件
清理已删除文件
Centos清理
#!/bin/sh
if ! [ -x "$(command -v lsof)" ]; then
echo 'lsof is not installed begin to install' >&2
yum install -y install lsof
fi
fdnum=$(lsof |grep delete|grep export|awk 'NR==1{print $2}')
if [ ! $fdnum ];then
echo 'lsof |grep delete|grep export|awk ...is null' >&2
return ;
fi
cd /proc/$fdnum/fd
filehd=$(ls -l|grep export|grep deleted|awk '{print $9}')
ARR=$filehd
echo "clean....";
echo $ARR
for element in $ARR;do
echo $element;
echo "0" > $element
done
Ubuntu清理
#!/bin/sh
if ! [ -x "$(command -v lsof)" ]; then
echo 'lsof is not installed begin to install' >&2
yum install -y install lsof
fi
fdnum=$(lsof |grep delete|grep export|awk 'NR==1{print $2}')
if [ ! $fdnum ];then
echo 'lsof |grep delete|grep export|awk ...is null' >&2
return ;
fi
cd /proc/$fdnum/fd
filehd=$(ls -l|grep export|grep deleted|awk '{print $9}')
ARR=$filehd
echo "clean....";
echo $ARR
for element in $ARR;do
echo $element;
echo "0" > $element
done;