How to find file accessed/created just few minutes ago

LinuxBashShellUnixFind

Linux Problem Overview


I always forget which file I edit one minutes ago, so I input find . -cmin 1 or some other value but it worked exactly 1 minutes. I had to try find . -ctime 2 /*or 3,4...*/.

Then I find another approach which be better:

touch -t 12251134 empty /*similar format which 5 or 10 minutes ago */
find . -newer empty

I can use date -d'-5minutes' +%m%d%H%M caculate the time for me. I want to know if there is a simple way to find files accessed 1, 2 or 3... minutes ago.

Linux Solutions


Solution 1 - Linux

Simply specify whether you want the time to be greater, smaller, or equal to the time you want, using, respectively:

find . -cmin +<time>
find . -cmin -<time>
find . -cmin  <time>

In your case, for example, the files with last edition in a maximum of 5 minutes, are given by:

find . -cmin -5

Solution 2 - Linux

If you have GNU find you can also say

find . -newermt '1 minute ago'

The t options makes the reference "file" for newer become a reference date string of the sort that you could pass to GNU date -d, which understands complex date specifications like the one given above.

Solution 3 - Linux

To find files accessed 1, 2, or 3 minutes ago use -3

find . -cmin -3

Solution 4 - Linux

If you know the file is in your current directory, I would use:

ls -lt | head

This lists your most recently modified files and directories in order. In fact, I use it so much I have it aliased to 'lh'.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionyuanView Question on Stackoverflow
Solution 1 - LinuxRubensView Answer on Stackoverflow
Solution 2 - LinuxsorpigalView Answer on Stackoverflow
Solution 3 - LinuxTadView Answer on Stackoverflow
Solution 4 - LinuxtimidpueoView Answer on Stackoverflow