Linux Grep记录了最近一个小时的日志

Linux Grep记录了最近一个小时的日志,linux,bash,shell,grep,Linux,Bash,Shell,Grep,我正在尝试对过去一小时内发生的日志进行grep,时间格式如下: 2020-11-0118:46:56 我试着运行这个: grep "^$(date -d -1 hour +'%Y-%m-%d %H')" postgresql-Mon.log | tail -n 100 但这不起作用。还有,在没有-n的情况下如何使用tail命令?我想从下到上grep,但是要得到最后一个小时的所有日志,而不仅仅是100条 请帮忙:> 我知道还有其他方法,但我需要grep命令 grep &quo

我正在尝试对过去一小时内发生的日志进行grep,时间格式如下: 2020-11-0118:46:56

我试着运行这个:

grep "^$(date -d -1 hour +'%Y-%m-%d %H')" postgresql-Mon.log | tail -n 100
但这不起作用。还有,在没有-n的情况下如何使用tail命令?我想从下到上grep,但是要得到最后一个小时的所有日志,而不仅仅是100条

请帮忙:>

我知道还有其他方法,但我需要grep命令

grep "$(date "+%Y-%m-%d %H" -d '1 hour ago')"
必须工作

[root@dell-shatov-dk ~]# cat ./test.log 
2020-11-02 07:21:10.104 t1
2020-11-02 08:21:10.104 t2
2020-11-02 09:21:10.104 t3
2020-11-02 10:21:10.104 t4
2020-11-02 11:21:10.104 t5
[root@dell-shatov-dk ~]# grep "$(date "+%Y-%m-%d %H" -d '1 hour ago')" test.log
2020-11-02 11:21:10.104 t5

[root@pg67日志]#cat test.log 2020-11-02 07:21:10.104 2020-11-02 08:21:10.104 2020-11-02 09:21:10.104 2020-11-02 10:21:10.104您有了新的mail-in/var/spool/mail/root[root@pg67日志]#grep$(日期“+%Y-%m-%d%H”-d“1小时前”)test.log grep:07:没有这样的文件或目录test.log:2020-11-02 07:21:10.104 test.log:2020-11-02 08:21:10.104 test.log:2020-11-02 09:21:10.104 test.log:2020-11-02 10:21:10.104[root@pg67日志]#日期周一11月2日08:55:02 UTC 2020
grep“$(日期“+%Y-%m-%d%H”-d'1小时前”)测试。日志
,抱歉,缺少引号如果灰色日期不在文件中,则此操作将失败。
tail-100
为tail,不带
n
grep "$(date "+%Y-%m-%d %H" -d '1 hour ago')" test.log