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

前端 未结 6 1722
栀梦
栀梦 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
    慢半拍i (楼主)
    2020-12-11 15:06

    I solved the problem this way: get the current date and last modified date of the file (both in unix timestamp format). Subtract the modified date from the current date and divide the result by 60 (to convert it to minutes).

    expr $(expr $(date +%s) - $(stat mail1.txt -c %Y)) / 60
    

    Maybe this is not the cleanest solution, but it works great.

提交回复
热议问题