tags:

views:

5509

answers:

5

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

+4  A: 

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
Greg Hewgill
+7  A: 

From the manual:

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

dirkgently
When I less a huge file then "G" to the bottom, it says "Calculating line numbers... (interrupt to abort)" even though it is not displaying line numbers. I'd like to know how to find out what line I'm on without exiting and relaunching with -N. I'm suffering the penalty. Where's the reward?
Richard Bronosky
wow, I have looked at the help for less dozens of times hoping to find the answer to this. I have always overlooked "-<flag> Toggle a command line option [see OPTIONS below]." ...which means you can type "-N" from within less. I have been annoyed by this for about a decade. Good times!
Richard Bronosky
you can type `-N` (show) and `-n` (hide) from within less to toggle line numbers.
rcoup
A: 

The canonical unix answer:

man less

lumpynose
+1  A: 

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

e.g.

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

sgargan
+1  A: 

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.

Matthew Jaskula
Passing -N or --LINE-NUMBERS only shows the date for me in CentOS 5.3. However using -N after starting less works fine.
Mike Miller