這段時間小編經常在幫忙打包服務器上的APK包,每一次手動的RM操作都太麻煩了,所以武林技術頻道小編編寫了一個腳本,這個腳本可以根據上次修改時間和指定目錄中的通配符匹配批量刪除,一起進入下文學習一下吧!
?
if [ $# -eq 0 ];then
??? echo "Usage: sh auto_clear_file.sh clear_filepath clear_regfilename filecreatetime"
??? echo "eg: sh auto_clear_file.sh /tmp/log/? user_log -7day"
??? exit
fi
filepath=$1
regfilename=$2
if [ "-$3" = "-" ];then
??? filectime=`date -d -7day '+ %s'`
else
??? filectime=`date -d $3 '+ %s'`
fi
log=`ls $filepath | grep $regfilename`
echo $log
for file in ${log}
do
??? echo $file
??? fileatime=`stat -c %X ${filepath}${file}`
??? if [ ${fileatime} -lt ${filectime} ]; then
??????? opt=`rm -f ${filepath}${file}`
??????? echo $opt
??? fi?
done
以上就是關于服務器自動刪除文件的腳本內容,大家學習到了多少呢?如果你還想了解更加專業的技術知識,你可以來武林技術頻道的網站具體了解哦。
新聞熱點
疑難解答
圖片精選