≡ Menu

Linux and Unix less command show line number

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
      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)
Share this tutorial on:

Examples and usage: less Command Display Line Numbers

{ 0 comments… add one }
Security: Are you a robot or human?
You can use these HTML tags and attributes: <strong> <em> <pre> <code> <a href="" title="">

   Tagged with: