Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/linux/28.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/logging/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Linux grep/touch-最近XX分钟内的mtime检查日志_Linux_Logging_Grep_Touch - Fatal编程技术网

Linux grep/touch-最近XX分钟内的mtime检查日志

Linux grep/touch-最近XX分钟内的mtime检查日志,linux,logging,grep,touch,Linux,Logging,Grep,Touch,我想在linux机器上运行查询。我想检查一个日志文件,并且只在最后15分钟内检查。假设日志文件发生了更改和添加。正确的查询是什么 grep“测试条件”/home/somelogpath/file.log-mtime 15 谢谢。要仅检查最近一小时内修改的文件,请执行以下操作: find /path/to/logfiles -mtime -1 -print 所以你可以 find /path/to/logfiles -mtime -1 -print | xargs grep "some condi

我想在linux机器上运行查询。我想检查一个日志文件,并且只在最后15分钟内检查。假设日志文件发生了更改和添加。正确的查询是什么

grep“测试条件”/home/somelogpath/file.log-mtime 15


谢谢。

要仅检查最近一小时内修改的文件,请执行以下操作:

find /path/to/logfiles -mtime -1 -print
所以你可以

find /path/to/logfiles -mtime -1 -print | xargs grep "some condition" /dev/null
(注意:我添加了一个文件(/dev/null),这样grep将始终至少有2个文件,因此将被迫显示匹配文件的名称。。由于它是/dev/null,它与grep中的任何内容都不匹配,因此您不会有seing“/dev/null”的风险在grep的输出中。但它有它的作用:grep将使用文件名作为任何匹配的前缀,即使只有1个文件匹配)

有关分钟等信息,请检查您的:

man find
(这取决于你的操作系统等)(而且我现在手头没有linux)


如果您的意思是“仅匹配日志文件中的最后X秒”:使用awk,并在行上设置一个条件(这取决于日志文件格式。如果它使用“启动后的秒数”或“历元数”,您可以简单地测试相关字段>=某个值。如果它使用“2014-05-15 hh:mm”,您也可以找到方法来执行此操作,但这会很麻烦

似乎不可能,除非每个记录都有时间戳,或者每个记录都记录在不同的文件中。