你可以使用标准的 GNU grep命令,但是这不会展示日志首行的元数据 。
如果你只想看包含你的 hello服务的日志记录,你可以指定时间来缩小范围 。举个例子,我将在我的测试虚拟机上以10:54:00为开始时间,这是上述的日志记录开始的分钟数 。注意--since=的选项必须加引号,这个选项也可以写成-S 某个时间 。
日期和时间可能在你的机器上有所不同,所以确保使用能匹配你日志中的时间的时间戳 。
[root@testvm1 ~]# journalctl --since=2020-05-10 10:54:00May 10 10:54:35 testvm1.both.org audit: BPF prog-id=54 op=LOADMay 10 10:54:35 testvm1.both.org audit: BPF prog-id=55 op=LOADMay 10 10:54:45 testvm1.both.org systemd[1]: Starting My hello shell script...May 10 10:54:45 testvm1.both.org hello.sh[1380]: ###############################May 10 10:54:45 testvm1.both.org hello.sh[1380]: ######### Hello World! ########May 10 10:54:45 testvm1.both.org hello.sh[1380]: ###############################May 10 10:54:45 testvm1.both.org systemd[1]: hello.service: Succeeded.May 10 10:54:45 testvm1.both.org systemd[1]: Finished My hello shell script.May 10 10:54:45 testvm1.both.org audit[1]: SERVICE_START pid=1 uid=0 auid=4294967295 ses=4294967295 msg='unit=hello comm=systemd exe=/usr/lib/systemd'May 10 10:54:45 testvm1.both.org audit[1]: SERVICE_STOP pid=1 uid=0 auid=4294967295 ses=4294967295 msg='unit=hello comm=systemd exe=/usr/lib/systemd/'May 10 10:56:00 testvm1.both.org NetworkManager[840]:since选项跳过了指定时间点的所有记录,但在此时间点之后仍有大量你不需要的记录 。你也可以使用until选项来裁剪掉你感兴趣的时间之后的记录 。我想要事件发生时附近的一分钟,其他的都不用:
[root@testvm1 ~]# journalctl --since=2020-05-10 10:54:35 --until=2020-05-10 10:55:00-- Logs begin at Tue 2020-05-05 18:11:49 EDT, end at Sun 2020-05-10 11:04:59 EDT. --May 10 10:54:35 testvm1.both.org systemd[1]: Reloading.May 10 10:54:35 testvm1.both.org audit: BPF prog-id=27 op=UNLOADMay 10 10:54:35 testvm1.both.org audit: BPF prog-id=26 op=UNLOADay 10 10:54:35 testvm1.both.org audit: BPF prog-id=55 op=LOADMay 10 10:54:45 testvm1.both.org systemd[1]: Starting My hello shell script...May 10 10:54:45 testvm1.both.org hello.sh[1380]: ###############################May 10 10:54:45 testvm1.both.org hello.sh[1380]: ######### Hello World! ########May 10 10:54:45 testvm1.both.org hello.sh[1380]: ###############################May 10 10:54:45 testvm1.both.org systemd[1]: hello.service: Succeeded.May 10 10:54:45 testvm1.both.org systemd[1]: Finished My hello shell script.May 10 10:54:45 testvm1.both.org audit[1]: SERVICE_START pid=1 uid=0 auid=4294967295 ses=4294967295 msg='unit=hello comm=systemd exe=/usr/lib/systemd>May 10 10:54:45 testvm1.both.org audit[1]: SERVICE_STOP pid=1 uid=0 auid=4294967295 ses=4294967295 msg='unit=hello comm=systemd exe=/usr/lib/systemd/>lines 1-46/46 (END)
推荐阅读
- 自来水总硬度的测定注意事项
- Linux使用虚拟机安装Windows 10的方法
- 如何在Linux上安装和使用Makeself
- Linux如何安装使用pidstat命令
- Linux如何使用setfacl命令创建权限文件
- Ubuntu使用SHA256检验iso镜像完整性的实例
- iphone xs max使用技巧 iphone xs max技巧有哪些
- 如何使用电视观看电视台直播
- 怎么缝衣服才能将线藏起来
- 学会使用粉饼
