2

For a MacOS and Ubuntu Server 20, with the command man less I can read the following:

 -n or --line-numbers
              Suppresses line numbers.  The default (to use line numbers) may cause less to run more slowly in some cases, especially with a very large input file.  Suppressing line  numbers  with
              the  -n  option will avoid this problem.  Using line numbers means: the line number will be displayed in the verbose prompt and in the = command, and the v command will pass the cur‐
              rent line number to the editor (see also the discussion of LESSEDIT in PROMPTS below).

 -N or --LINE-NUMBERS
              Causes a line number to be displayed at the beginning of each line in the display.

The reason of this post is about the -n (lowercase) parameter that contains the The default (to use line numbers) part. For the both OS mentioned if I did do:

  • less /path/to/filename.txt

It displays the data without the line numbers, it is the contrary as indicated above.

Of course If I want see the line numbers I use:

  • less -N /path/to/filename.txt

It works as indicated. Therefore:

less    /path/to/filename.txt
less -n /path/to/filename.txt

Is practically the same.

Am I missing something?

BTW with less --help

-n  -N  ....  --line-numbers  --LINE-NUMBERS
                  Don't use line numbers.

Not very clear, is confuse.

I created this post due the following valuable post:

Where indicates in the solution:

You can, however, run "less -n +F", which causes "less" to read 
only the end of the file, at the cost of **not** displaying line numbers

1 Answer 1

3

less displays line numbers in two ways:

  • at the start of each line, if -N is used;
  • in the status line at the bottom of the screen, when verbose prompts are enabled (less -M; this will show the number of the first line shown, the last line shown, and the total number of lines).

-n disables the latter, as well as the former. In particular, determining the total number of lines can be expensive; that’s why the option is useful. When line numbers are disabled using -n, less shows the position in the file in bytes.

My version of less has the following in less --help:

  -n  ........  --line-numbers
                  Don't use line numbers.
  -N  ........  --LINE-NUMBERS
                  Use line numbers.

The behaviour of -n is described in the information you show:

Using line numbers means: the line number will be displayed in the verbose prompt and in the = command, and the v command will pass the current line number to the editor

This doesn’t mention line numbers at the start of each line.

0

You must log in to answer this question.

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