
MacOS나 Debian 등에서 지난 x초 동안 파일이 수정되었는지 확인하고 싶습니다.
is_file_older_than() {
seconds="$1"
file="$2"
echo "The file $file"
modified_secs="$(date -r "$file" +%s)"
current_secs="$(date +%s)"
diff="$(expr "$current_secs" - "$modified_secs")"
if [[ "$diff" -gt "$seconds" ]]; then
return 0
fi
return 1
}
if is_file_older_than 3 "$BASH_SOURCE"; then
echo 'old'
else
echo 'young'
fi
하지만 100% 작동하는지, 신뢰할 수 없는 부분이 있는지 확인하는 데 어려움을 겪고 있습니다. 작동하는 것 같습니다.