2
1
I know less +/pattern filename
will open the file and navigate to the first occurrence of the pattern. Is there a way to tell less
to search from the end backwards? Does it even accept more than one +
switch?
Do not work:
less +?pattern filename
less +G +?pattern filename
The man page does not state so explicitly, and the syntax you provided does not lead to the desired result. It works, in a sense that the same thing happens as if you were to open the file and try searching backwards - you get "Pattern not found". Backward search does not jump to the end of the file when you are on the first line of the file. Hence, I tried
less +G +?pattern filename
, but then again, reading theman
page, it appears that only one+cmd
is allowed. So, it appears that there is no way to achieve what I'm looking for. – ultracrepidarian – 2017-12-21T20:10:31.817I do not understand what you want to do. Can you provide an example? The syntax I provided above looks for a term starting at the last line of the file and searches upwards. – davidmneedham – 2017-12-21T20:22:01.313
Try
less +/cd .bash_history
vs.less +?cd .bash_history
. The first example opens the file and navigates to the first occurrence ofcd
in your bash history (hopefully you have them). The second example does nothing, except open the file, as if it'sless .bash_history
. – ultracrepidarian – 2017-12-21T20:33:42.277less +?cd .bash_history
on my system shows the latest occurrence ofcd
in my bash history. Perhaps you have theLESS
environmental variable set in a way that is overriding what I'm expecting? – davidmneedham – 2017-12-21T20:36:26.707It does nothing on mine.
$LESS
is not set. – ultracrepidarian – 2017-12-21T20:52:07.557Got it. Something to do with bash expansion probably. It works when the command is quoted:
less +'?cd' .bash_history
. – ultracrepidarian – 2017-12-21T21:00:28.847