bash 需要查找 15 到 5 分钟前修改过的文件

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/18260154/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-18 06:16:27  来源:igfitidea点击:

Need to find files modified between 15 and 5 minutes ago

bashscriptingfind

提问by Arthur

I'm trying to find all files in a given folder that were modified withing a certain time frame, say between 5 and 15 minutes ago.

我正在尝试查找给定文件夹中在特定时间范围内(例如 5 到 15 分钟前)修改过的所有文件。

Currently I can find anything modified say up to 15 minutes ago by using find -cmin

目前,我可以使用 find -cmin 找到最多 15 分钟前修改过的任何内容

#!/bin/bash

minutes="15"

FILETYPES=`find . *PATTERN*.txt* -maxdepth 0 -type f -cmin -$minutes`

How do I give it a time frame?

我如何给它一个时间框架?

回答by Gilles Quenot

Try this :

尝试这个 :

find . -name '*pattern.txt' -maxdepth 1 -type f \( -mmin -15 -a -mmin +5 \)

Notes

笔记

  • the parenthesis are not mandatory here with and: -a, but it's necessary for case with or: -o
  • always use single quotes around the pattern to prevent shell expansion of the wildcard
  • to give a pattern, use -nameor -iname
  • for the date/hour, -mminis the way to go for minutes and -mtimefor days.
  • 括号不是强制性这里-a,但它是必要的情况下使用-o
  • 始终在模式周围使用单引号以防止通配符的外壳扩展
  • 给出一个模式,使用-name-iname
  • 对于日期/小时,-mmin是几分钟和-mtime几天的方式。

回答by jordanm

Using find, you can add additional conditions to create the range. Each condition is implied as "and" unless -ois used. You also want -mmininstead of -cminfor modified time (but they are often the same).

使用find,您可以添加其他条件来创建范围。每个条件都隐含为“和”,除非-o使用。您还想要-mmin代替-cmin修改时间(但它们通常是相同的)。

find . '*PATTERN*.txt*' -maxdepth 0 -type f -mmin -15 -mmin +5