Linux and Unix less command show line number

Fig. 01: less displaying the line numbers

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, enter:

less -N

Sample outputs:

      1 #!/usr/bin/python
      2 import os
      3 #import sys
      5 filename=raw_input("Type file name to remove: ")
      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)

Examples and usage: less Command Display Line Numbers

Leave a Comment