Find out if file has been modified within the last 2 minutes

前端 未结 6 1724
栀梦
栀梦 2020-12-11 14:51

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 <

6条回答
  •  旧时难觅i
    2020-12-11 15:08

    Here's an even simpler version that uses shell math over expr:

    SECONDS (for idea)

    echo $(( $(date +%s) - $(stat file.txt  -c %Y) ))
    

    MINUTES (for answer)

    echo $(( ($(date +%s) - $(stat file.txt  -c %Y)) / 60 ))
    

    HOURS

    echo $(( ($(date +%s) - $(stat file.txt  -c %Y)) / 3600 ))
    

提交回复
热议问题