Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm trying to run less in Linux, and I want it to search for something immediately after launch.

It's basically like doing this:

$ less

Then press '/', type a search pattern like "^commit \w+$", then press enter, and press 'n' to find each subsequent result.

I'd like less to be launched, and then search for a pattern. There doesn't seem to be anything in the man page about starting with a pattern, but perhaps you can send it commands like Vim.

share|improve this question
Awesome, put this in your git config: core.pager = less -cFRX --pattern='^commit' and you'll be able to go to the next commit with the 'n' key right away. – Neil Aug 19 '10 at 2:37
up vote 4 down vote accepted

From the man page:

   -ppattern or --pattern=pattern
          The  -p  option  on the command line is equivalent to specifying
          +/pattern; that is, it tells less to start at the  first  occur-
          rence of pattern in the file.

This works as expected using the latest version of less (436).

share|improve this answer

You can use + to send arbitrary commands. E.g.:

less +/pattern

-p PATTERN (as posted by nik) is equivalent to +/PATTERN.

share|improve this answer
I prefer this answer, because it is more complete. The option +/pattern is equivalent to --pattern=pattern, but it can do more, such as to start less at the end of a file, do less +G. The + option gives you everything -p|--pattern does plus the entire set of other commands to run in less, so I say don't bother remembering -p and just use +/ to search just as you would from inside less. – DrStrangepork Jul 28 '15 at 18:26

You mean like?

less -p PATTERN filename

That is in the manual.

share|improve this answer

There is indeed somthing in the less manpage.

You could try :

less -p<pattern>


less --pattern=<patern>
share|improve this answer

There are actually two ways to do this. As everyone else mentioned, you can use the -p/--pattern options:

less -p<pattern>
less --pattern=<pattern>

Your pattern will have to be wrapped in quotation marks since it contains a space.

However, there is actually a second way to do this:

LESS=-p<pattern> less
LESS=--pattern=<pattern> less

The second method has one distinct advantage. It can be used with other commands that use less for pagination!:

LESS=-p"^       read \[" man bash

This can quite literally be extended to search the bash man page for all builtin commands. I got a little carried away one day and "fixed" man for bash builtins.

share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .