Linux and Unix less command show line number

by on February 28, 2014 · 0 comments· LAST UPDATED February 28, 2014

Fig. 01: less displaying the line numbers

The less a terminal program on Linux and Unix-line system to view text files. It can displays line numbers for source code viewing or other purpose on screen. The syntax is:

less -N /path/to/file

To shows line numbers for remove.py, enter:

less -N remove.py

Sample outputs:

      1 #!/usr/bin/python
      2 import os
      3 #import sys
      4
      5 filename=raw_input("Type file name to remove: ")
      6
      7 if os.path.exists(filename):
      8         try:
      9                 os.remove(filename)
     10         except OSError, e:
     11                 print ("Error: %s - %s." % (e.filename,e.strerror))
     12 else:
     13         print("Sorry, I can not find %s file." % filename)
TwitterFacebookGoogle+Found an error/typo on this page? Help us!

Examples and usage: less Command Display Line Numbers

{ 0 comments… add one now }

Leave a Comment

Tagged as: