删除 /tmp 目录下长时间未访问的文件
#!/bib/bash
DIR=/tmp
cd $DIR || {
echo "Dir not Found: $Dir"
exit
}
echo "Delete a file from 90 days if it is not in use, skip hidden files. "
ff="$(find /tmp -atime +90 -type f)"
num=$(echo "$ff" | wc -l)
echo "Total FIles Num: $num"
echo "$ff" | grep -v "/\." | grep /tmp | while read f
do
lsof $f || {
echo "Delete this file: $f"
find $f -delete
num=$(($num-1))
echo "Num of files to be Delete: $num"
}
done

浙公网安备 33010602011771号