Finding the files which are not accessed/modified

2019-05-18 10:44发布

问题:

I've one requirement, i want to give the notifications to the users who have not accessed the files in 30 min. using the shell script. Is it possible to find the files which was not accessed in 30 min using find. I'd checked.

find /opt/SP/tibmft/scripts/ -mtime 0

which will fetch the files which was modifed in last 24 hours.

My requirement is fetch the files which was created in the last 30 min and not been accessed by the user? Please suggest the solution, how to achieve this?

回答1:

Try using

find PATH -cmin -30 -and -amin +30


回答2:

Is it possible to find the files which was not accessed in 30 min using find.

According to man find:

Numeric arguments can be specified as

  • +n for greater than n,
  • -n for less than n,
  • n for exactly n.

Please note, this is greater and less not greater/less or equal. So, you have to take some care in order to not have a 1 minute error due to that:

find PATH -not -amin +30

or

find PATH -amin -31

My requirement is fetch the files which was created in the last 30 min and not been accessed by the user?

Here is an attempt:

find PATH -amin -31 -not -newerBt "-30 minutes"
#                        ^^^^^^^^
#                        (B)irth date newer (t)han ...

... unfortunately, it does not work on my computer with ext4 file-system, as, to quote a comment by Barmar above: "Most Unix file-systems don't record file creation time. They just have modification, access, and inode change times."

Some random ideas:

  • According to one of your comment, this is potentially a periodic task. So one might investigate the use of a cron job to record the list of files at regular intervals?
  • If your file-system has snapshots you might build on that too. Maybe.


回答3:

Try the following:

find $PATH -type f -cmin -30 amin +30


标签: bash shell