Linux下删除无用的(很久没有访问或者修改)的文件

来源:互联网 发布:阿里云生态合作伙伴 编辑:程序博客网 时间:2024/05/16 07:05
#!/bin/bash##path="/root"path=$1if [ ! -d $path ]; then ##判断目录是否存在    echo "Directory '$path' does not exist Or '$path' is not a directory!"    exit 0fiif [ ! -x $path -o ! -r $path ]; then   ##验证用户对目录是否有足够权限    echo "You have no right to  read the directory '$path'!"    exit 0 fideclare -i dayStr=86400 #一天时间的秒数declare -i day=7interval=$(($dayStr*$day)) #时间间隔for file in $path/* ##遍历目录do     if [ -f $file ]; thenatime=`stat -c %X $file`##文件最近一次的访问时间dtime=`date +%s`##系统时间    if [ $[ $dtime - $atime ] -gt $interval ]; thenrm -f $file    fi    fidone

0 0
原创粉丝点击