ablog

不器用で落着きのない技術者のメモ

bash でファイルの最終更新時刻が現在と同じ時間か調べる方法

$ touch a
$ touch b -t `date -d "-1 days" '+%Y%m%d%H%M'`
$ ls -l 
total 0
-rw-r--r-- 1 oracle oinstall 0 Feb  3 16:10 a
-rw-r--r-- 1 oracle oinstall 0 Feb  2 16:10 b

$ ls|while read line
do
	if [ "`stat --print=%y $line|perl -ple 's/([0-9\-:\s]{13}).*/\1/'`" == "`date '+%Y-%m-%d %H'`" ]; then
		echo "$line is modified within an hour."
	else
		echo "$line is not modified within an hour."
	fi
done

a is modified within an hour.
b is not modified within an hour.