蓝天

查找被删除但仍然占据磁盘的文件

下载:https://github.com/eyjian/libmooon/blob/master/shell/find_deleted_files.sh

#!/bin/sh
# 查找被删除但仍然占据磁盘的文件

dirs=(`ls -l --time-style=long-iso /proc 2>/dev/null | awk '{ print $8 }' 2>/dev/null`)
for ((i=0; i<${#dirs[@]}; ++i))
do
  dir=${dirs[i]}
  if test -z "$dir"; then
    continue
  fi
  $(expr $dir + 0 > /dev/null 2>&1)
  if test $? -ne 0; then
    continue
  fi

  pid=$dir
  lsof -p $pid 2>/dev/null | grep "deleted" | grep -v "$0"
done

效果
# find_deleted_files.sh
hello 13921 root 1u CHR 136,7 0t0 10 /dev/pts/7 (deleted)
world 13950 zhangsan 0u CHR 136,13 0t0 16 /dev/pts/13 (deleted)

posted on 2020-09-07 10:08  #蓝天  阅读(206)  评论(0编辑  收藏  举报

导航