Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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
1  
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

4 Answers 4

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

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>

or

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

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.