我喜欢如何less
使用+
命令行中的-parameter添加命令。我喜欢这样的即时搜索:
$ less +/DHCP /var/log/syslog
# result: syslog at the point of the first occurrence of DHCP
Run Code Online (Sandbox Code Playgroud)
但我也喜欢将它设置为遵循这样的输出:
$ less +F /var/log/syslog
# result: a syslog that follows the file, very much like tail -f would.
Run Code Online (Sandbox Code Playgroud)
但每隔一段时间我都喜欢两者。但我不知道该怎么做。
$ less +F +/DHCP /var/log/syslog
# result: "Pattern not found" - it will actually bunch up both things to one string.
Run Code Online (Sandbox Code Playgroud)
任何能告诉我如何自动过滤而无需在开始时按的人的奖励积分?
$ less +\&DHCP /var/log/syslog
# result: "please press enter" after which the filtering search _is_
# running correctly. I would love to get rid of that extra <enter>
Run Code Online (Sandbox Code Playgroud)
编辑2:有趣的是,我可以结合这些:
$ less +?DHCP +G /var/log/syslog
# result: jumps to the end and reverse-searches for DHCP
# But I have to press enter (which I'd like to avoid)
Run Code Online (Sandbox Code Playgroud)
但我不能这样做:
$ less +G +?DHCP /var/log/syslog
# this is being bunched up to ?DHCPG and subsequently not found.
Run Code Online (Sandbox Code Playgroud)
那么,顺序似乎很重要,所有字符串都被解释为好像是一个?
编辑这里是我系统上安装的 less 版本,但如果需要,我愿意安装另一个版本!
$ less --version
less 458 (GNU regular expressions)
Copyright (C) 1984-2012 Mark Nudelman
[...]
Run Code Online (Sandbox Code Playgroud)
根据您后来的评论,我认为我没有理解您问题的第一部分。对我来说,使用less +F +/pattern logfile
作品并继续突出pattern
显示更新文件中出现的新实例。
至于问题的奖励部分,您可以尝试以下命令之一:
less +\&DHCP$'\n' /var/log/syslog
Run Code Online (Sandbox Code Playgroud)
或者
less +\&DHCP^M /var/log/syslog
Run Code Online (Sandbox Code Playgroud)
在第二个命令中,^M
通过按下Ctrl-V
then生成Enter
。除非您要编写脚本或其他内容,否则在 less 开始时按 Enter 会更容易一些。