Find a file which is 30 minutes old

On Linux, there is no track of the creation time of a file. You can only access:

  • the last modification time of the content (a creation counts as a modification of course), mtime,
  • the last access time, atime,
  • the last modification time of the meta-data, ctime.

If you want to look for files with a test based on these times, find (man find) can help you.

You would use it this way to find a file accessed exactly 30 minutes ago in your current directory and its subdirectories:

find -amin 30

Usually, you'll want to use an interval as it can be difficult to give an exact number of minutes:

find -amin +25 -amin -35

This will find files accessed more than 25 but less than 35 minutes ago.

And if you're interested only in modification time and not in access (i.e. read) time, replace -amin with -mmin.


With out GNU/BSD find

TZ=ZZZ0 touch -t "$(TZ=ZZZ0:30 date +%Y%m%d%H%M.%S)" /reference/file

and then find . -newer /reference/file

solution given by Stéphane Chazelas


You can use mtime to do so:

find . -mmin 30    #exactly 30 minutes old

Tags:

Find