How to determine if file has been modified in the last x seconds
1
vote
1
answer
257
views
I want to determine if a file has been modified in the last x seconds on MacOS or Debian etc.
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
but I am trouble verifying if it's working 100% and if there's anything unreliable - it looks like it's working
Asked by Alexander Mills
(10744 rep)
Aug 28, 2019, 10:02 PM
Last activity: Oct 13, 2024, 03:51 PM
Last activity: Oct 13, 2024, 03:51 PM