Tutorial :How to display line numbers in less (GNU)?



Question:

Does somebody know the command to make less display line numbers in the left column?


Solution:1

From the manual:

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

You can also toggle line numbers without quitting less by typing -N.

It is possible to toggle any of less's command line options in this way.


Solution:2

You can also press = while less is open to just display (at the bottom of the screen) information about the current screen, including line numbers.


Solution:3

You could filter the file through cat -n before piping to less:

cat -n file.txt | less  

Or, if your version of less supports it, the -N option:

less -N file.txt  


Solution:4

You can set an enviroment variable to always have these options apply to all less'd file:

export LESS='-RS#3NM~g'  


Solution:5

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

You can also toggle line numbers without quitting less by typing -N<return>. It it possible to toggle any of less's command line option in this way.


Solution:6

If you hit = and expected to see line numbers, but only see byte counts, then line numbers are turned off. Hit -n to turn them on, and make sure $LESS doesn't include 'n'.

Turning off line numbers by default (eg. setting LESS=n) speeds up searches in very large files. Handy if you frequently search through big files but don't usually care which line you're on.

I typically run with LESS=RSXin (escape codes enabled, long lines chopped, don't clear the screen on exit, ignore case on all lower case searches, no line number counting by default) and only use -n or -S from inside less as needed.


Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Previous
Next Post »