Less command in Linux is used to read the contents of a text file one page at a time at the terminal. It is useful for reading large text file because it accesses the file page by page rather than loading the complete file. This results in faster loading and the file can be browsed line by line or section by section.

  • It allows users to navigate both forward and backward through the file.

In this tutorial, you will learn about less command and uses of less command with examples.

Syntax of less Command

less [options] filename

There are many options with less command, you can find all options available with less command using the command less --help

less --help

less --help
1. Open a txt file with less

Using the less filename command, The file’s first few lines are shown in the terminal. The file name and path are displayed in the bottom-left corner of the screen.

  • You may have trouble figuring out how to exit less, press ‘q’ to exit from less.
  • You may see empty blank lines at the top, if you try to display a short text file with less.
less filename

less filename
2. Display line number

You can display the line numbers in the less command. Use  -N option with less to show line numbers for the provided text file.

less -N filename

less -N filename
3. Find string

It may be a tough task to find any string or pattern in a large text file. less command allows us to search for a specific piece of text. To find any string or pattern press / (forward_slash) to initiate a forward search and type whatever you want to find.

less forward slash

less command forward slash search

less questionmark

less command search question mark

less pin filename

less -Psearch_text filename

less command with multiple blank line file

less filename command in Linux having blank line

less -s filename

less -s filename with a file having space

less file1 file2

less command multiple file

less multiple file accessing second file

less command multiple files accessing the second file

less -x filename

less -x filename

less +F filename

less +F filename

sudo dmesg less

sudo dmesg less



Linux command with examples

A


adduser  |  addgroup  |  alias  |  anacron  |  apt  |  aptitude  |  arp  |  at atq  |  atrm  |  awk


B


basename banner | batch |  bc  |  bg  |  bzip


C


cat cal  |  cd  |  chgrp  |  chown  |  cksum  |  chmod  |  clear  |  cmp  |  comm  |  cp


D


date  |  dd  |  df  |  diff  |  dir  |  dmidecode  |  du


E


echo  |  eject  |  env  |  exit  |  expr


F


factor  |  find  |  free


G


grep  |  groups  |  gunzip  |  gzip


H


head  |  history  |  hostname  |  hostnamectl  |  htop  |  hwclock  |  hwinfo


I


id  |  ifconfig  |  ionice  |  iostat  |  ip  |  iptables  |  iw  |  iwlist


J


K


kill  |  kmod


L


last  |  less  |  ln  |  locate  |  login  |  lp  |  ls  |  lshw  |  lscpu  |  lsof  |  lsusb


M


man  |  mdsum  |  mkdir  |  more|  mv


N


nano  |  nc  |  neofetch  |  netcat  |  netstat  |  nice  |  nmap  |  nproc


O


openssl


P


passwd  |  pidof  |  ping  |  pr  |  ps  |  pwd  |  pstree


Q


R


rdiff-backup  |  reboot  |  rename  |  rm  |  rmdir


S


scp  |  shred  |  shutdown  |  sleep  |  sort  |  split  |  ssh  |  stat  |  su  |  sudo  |  sum


T


tac  |  tail  |  talk  |  tar  |  tee  |  time  |  tree  |  top  |  touch  |  tr


U


unalias  |  uname  |  uniq  |  unzip  |  uptime  |  users


V


vim  |  vi


W


w  |  wall  |  watch  |  wc  |  wget  |  whatis  |  whereis  |  which  |  who  |  whoami


X


xargs


Y


yes  |  youtube-dl


Z


zcmp  |  zdiff  |  zip  |  zz

Sharing is Caring
Scroll to Top