In a bash script I want to check if a file has been changed within the last 2 minutes.
I already found out that I can access the date of the last modification with <
Here is a solution that will test if a file is older than X seconds. It doesn't use stat, which has platform-specific syntax, or find which doesn't have granularity finer than 1 minute.
interval_in_seconds=10
filetime=$(date -r "$filepath" +"%s")
now=$(date +"%s")
timediff=$(expr $now - $filetime)
if [ $timediff -ge $interval_in_seconds ]; then
echo ""
fi