Linux 如何查找几分钟前访问/创建的文件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/14032188/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to find file accessed/created just few minutes ago
提问by yuan
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...*/
.
我总是忘记一分钟前我编辑了哪个文件,所以我输入find . -cmin 1
或其他一些值,但它工作了1
几分钟。我不得不尝试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.
我可以date -d'-5minutes' +%m%d%H%M
为我计算时间。我想知道是否有一种简单的方法可以找到在 1、2 或 3 分钟前访问过的文件。
采纳答案by Rubens
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:
例如,在您的情况下,最多 5 分钟内最新版本的文件由以下给出:
find . -cmin -5
回答by Tad
To find files accessed 1, 2, or 3 minutes ago use -3
要查找 1、2 或 3 分钟前访问过的文件,请使用 -3
find . -cmin -3
回答by timidpueo
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'.
这会按顺序列出您最近修改的文件和目录。事实上,我经常使用它,以至于将它别名为“lh”。
回答by sorpigal
If you have GNU find you can also say
如果你有 GNU find 你也可以说
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.
这些t
选项使参考“文件”newer
成为您可以传递给 GNU 的那种类型的参考日期字符串,GNUdate -d
可以理解上面给出的复杂日期规范。