在指定时间内不停刷新目录下文件的时间戳

清华大佬耗费三个月吐血整理的几百G的资源,免费分享!....>>>

#!/bin/sh
#Usage : run script under certain directory, to keep files under this directory fresh
#Example: nohup keepAlive 1.5&
#Note: directory should have permission to write files under current directory

#Visit given directory recursively and use touch command to update the timestamp of all files in it
function freshDir() {
	for file in `ls $1`
	do
        touch $1"/"$file
		if [ -d $1"/"$file ]
		then
			freshDir $1"/"$file
		fi
	done
}

#Show help when script started without arguments
function showHelp() {
	echo "Run script under certain directory, to keep files under this directory up to date and not be deleted"
	echo "Example: nohup ~yantang/tools/keepAlive 1.5&"
	echo "Then all files under current directory will be refreshed in the next 1.5 days "
	echo "Kill it manually when you no longer need it"
}

if [ $# -gt 0 ]
then
	daysAlive=$1
else
	showHelp
	exit
fi

curDate=`date`
echo "The time now: $curDate"
echo "The directory will be alive for $daysAlive days"

startTime=`date +%s`
currentTime=$startTime
typeset days=$(echo ${currentTime} ${startTime}|awk '{print ($1-$2)/86400 }')

isAlive=1

while [ $isAlive -gt 0 ]
do
	freshDir "."
	sleep 600    #Sleep 10 minutes
	currentTime=`date +%s`
	days=$(echo ${currentTime} ${startTime} | awk '{print ($1-$2)/86400 }')
	isAlive=$(echo ${days} ${daysAlive}|awk '{if($1<$2) print 1; else print 0;}')
done

curDate=`date`
echo "Now the time is $curDate .keepAlive stopped running. Bye"