如何找到几分钟前访问/创建的文件

我总是忘记一分钟前我编辑了哪个文件,所以我输入 find . -cmin 1或其他值,但它工作正好是 1分钟。我得试试 find . -ctime 2 /*or 3,4...*/

然后我找到了另一种更好的方法:

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

我可以用 date -d'-5minutes' +%m%d%H%M为我计算时间。我想知道是否有一个简单的方法可以找到123分钟前访问过的文件。

132132 次浏览

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

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

find . -cmin -3

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'.

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.