脚本工具
清理超时文件以及文件夹
#!/usr/bin/env bash
let time=3600*24*180
function clear(){
# shellcheck disable=SC2045
for file in ` ls $1 `
do
if [ -d $1"/"$file ];then
clear $1"/"$file
else
a=`stat -c %Y $1"/"$file`
b=`date +%s`
if [ $[ $b - $a ] -gt $time ];then
# shellcheck disable=SC2115
rm -vrf $1"/"$file
fi
fi
done
}
function clearDir(){
if [ -d $1 ];then
# shellcheck disable=SC2045
for f in ` ls $1 `
do
file=$1$f
a1=`stat -c %Y $file`
b1=`date +%s`
if [ $[ $b1 - $a1 ] -gt $time ];then
rm -vrf $file
fi
done
else
echo "目录不存在"
fi
}
dirPath1=$1
clear $dirPath1
clearDir $dirpath1
定期清理固定目录
#!/usr/bin/env bash
##******************************************************************************
## ** 文件名称: clear_outdate_files.sh
## ** 功能描述: 采集脚本清理
## **
## ** 创建者: liwf
## ** 创建日期: 2022/10/13
## ** 修改日志:
## ** 修改日期:
## ** ---------------------------------------------------------------
## 采集数据目录清理-保留3个月,当前已经清理完202206及以前的数据
## 清理示例:
## rm -vrf /data/nas/dyxpt_dl/pageposter/format/202206*;
## rm -vrf /data/nas/dyxpt_dl/channeluser/202206*;
## 查看目录下文件
## ls -l /data/nas/dyxpt_dl/channeluser/;
## 查看目录下文件以及文件夹大小
## path='/data/nas/dyxpt_dl/'
## cd ${path}
## du -sh *
#*******************************************************************************
dayid=$1
rm -vrf /data/nas/dyxpt_dl/gameIop/$dayid;
rm -vrf /data/nas/dyxpt_dl/musicIop/$dayid;
rm -vrf /data/nas/dyxpt_dl/videoIop/$dayid;
rm -vrf /data/nas/dyxpt_dl/readIop/$dayid;
rm -vrf /data/nas/dyxpt_dl/pageposter/format/$dayid;
rm -vrf /data/nas/dyxpt_dl/channeluser/$dayid;
rm -vrf /data/nas/dyxpt_dl/material/$dayid;
rm -vrf /data/nas/dyxpt_dl/material/format/$dayid;
rm -vrf /data/nas/dyxpt_dl/shortlog/$dayid;
rm -vrf /data/nas/dyxpt_dl/shortlog/format/$dayid;
rm -vrf /data/nas/dyxpt_dl/shortlog/new/$dayid;
rm -vrf /data/nas/dyxpt_dl/shorturl/$dayid;
rm -vrf /data/nas/dyxpt_dl/shorturl/format/$dayid;
rm -vrf /data/nas/dyxpt_dl/winning_result/$dayid;