#!/bin/bash
##path="/root"
path=$1
if [ ! -d $path ]; then ##判断目录是否存在
echo "Directory '$path' does not exist Or '$path' is not a directory!"
exit 0
fi
if [ ! -x $path -o ! -r $path ]; then ##验证用户对目录是否有足够权限
echo "You have no right to read the directory '$path'!"
exit 0
fi
declare -i dayStr=86400 #一天时间的秒数
declare -i day=7
interval=$(($dayStr*$day)) #时间间隔
for file in $path/* ##遍历目录
do
if [ -f $file ]; then
atime=`stat -c %X $file` ##文件最近一次的访问时间
dtime=`date +%s` ##系统时间
if [ $[ $dtime - $atime ] -gt $interval ]; then
rm -f $file
fi
fi
done
Linux下删除无用的(很久没有访问或者修改)的文件
最新推荐文章于 2024-05-17 20:45:00 发布