Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. 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

Please consider the following example:

$ grep --color=always -n 'Format\|Files' /usr/share/doc-base/doc-base | less -R

Here, grep will color also the line numbers of the matches, and less will display it.

I know I could show the entire file with line numbers in less with:

$ less -N /usr/share/doc-base/doc-base 

My question is - is there a way, to get less to display the entire file with line numbers - but where the line numbers are colored (as in the case with the grep output)?

Many thanks in advance for any answers,

share|improve this question

Well, found something related to the above example - just have grep additionally match "start of line" (^), and all non-matching lines will pass "unharmed", with only the line numbers colored:

$ grep --color=always -n 'Format\|Files\|^' /usr/share/doc-base/doc-base | less -R

... (and as a bonus, matches stay highlighted).

However, I'd still like to know if less can be persuaded to do this "natively"?

share|improve this answer

Your Answer


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.