`less` “search backward” command line switch

less

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

Best Answer

The man page for less states the syntax is less +?pattern filename

?pattern
       Search  backward  in  the  file for the N-th line containing the
       pattern.  The search starts at the last line displayed (but  see
       the -a and -j options, which change this).

Press n to continue to search for the pattern backwards. Press N to search for the pattern forwards.

Example

For testfile.txt of

apple
banana
carrot
apple
banana
carrot
apple
banana
carrot

less +?banana testfile.txt shows the following:

banana
carrot
Related Question