What I know and use regularly
I love how I can add commands to less
with the +
-parameter from the commandline. I like this for instant searching:
$ less +/DHCP /var/log/syslog
# result: syslog at the point of the first occurrence of DHCP
Yet I also like to set it to follow the output like this:
$ less +F /var/log/syslog
# result: a syslog that follows the file, very much like tail -f would.
What I would like to use
But every once in a while I'd like BOTH. But I do not have any Idea how to do it.
$ less +F +/DHCP /var/log/syslog
# result: "Pattern not found" - it will actually bunch up both things to one string.
Bonus Points to anyone who can tell me how I can automatically filter without having to press at the beginning?
$ 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>
edit2: Funny is, that i can combine these:
$ 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)
but i can not do this:
$ less +G +?DHCP /var/log/syslog
# this is being bunched up to ?DHCPG and subsequently not found.
So, the order seems to be important, and all strings are interpreted as if it was one?
Version info
edit here's the version of less installed on my system, but i'd be willing to install another version if neccessary!
$ less --version
less 458 (GNU regular expressions)
Copyright (C) 1984-2012 Mark Nudelman
[...]
Best Answer
I don't think I understand the first part of your question based on your later comments. For me, using
less +F +/pattern logfile
works and continues to highlight new instances ofpattern
as they appear in the updated file.As for the bonus part of your question, you can try one of the following commands:
or
In that second command the
^M
is generated by pressingCtrl-V
thenEnter
. Kinda easier to just press enter when less starts though unless you're looking to script it or something.