如何从命令行将多个“+”命令添加到less中

ame*_*hes 5 command-line less

我所知道和经常使用的

我喜欢如何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)

del*_*ray 8

根据您后来的评论,我认为我没有理解您问题的第一部分。对我来说,使用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-Vthen生成Enter。除非您要编写脚本或其他内容,否则在 less 开始时按 Enter 会更容易一些。

  • 这太棒了!我可以`less +\&amp;\!DHCP^M/kernel^MSF /var/log/syslog` - 这将:删除所有带有DHCP的行,搜索(并突出显示)内核,切长行并跟踪文件。非常感谢! (2认同)