• Home
  • Linux
  • Ubuntu
  • Debian
  • CentOS
  • Linux Commands
  • About Us
  • Donate
TecNStuff
Menu
  • Home
  • Linux
  • Ubuntu
  • Debian
  • CentOS
  • Linux Commands
  • About Us
  • Donate

Less Command in Linux

Written by Admin, Updated On December 20, 2019
less, terminal
Less Command in Linux

Less command is used to display contents of any output of command or a file in a single page at a time. Using it you can navigate to backward and forward through the file or output.

Less will read file page by page instead of entire files so it will load fast compare to text editors like nano or vim. Mostly, less is used to view contents of large files.

Use of Less#

Below is the syntax to use the less program:

less [OPTIONS] filename

Let’s take an example, we will view the content of file /usr/share/common-licenses/GPL-3, type:

less /usr/share/common-licenses/GPL-3

It will show output as given below:

less-command-file

Navigating to the File Content#

Once you use the less command to view content of a large file, you will see a colon (:) at end of terminal.

If you would like to go to next pages just press the f key or space bar in keyboard. If you want to go to specific line then enter the number followed by space or f key. Alternatively, you can press Enter or Down arrow key to scroll forward by a line a Up arrow to scroll backward.

Use the b key to go previous page. You can move up for a specific number of line by entering number followed by b key. You also can search for a specific pattern using forward slash (/) followed by pattern whatever you want to search. By pressing the Enter key less will search forward for match cases. If you would like to search backwards use (?) followed by pattern.

You will see (END) once once the file reach to the end of file. Press q key to quite the less.

Less Options#

You can pass few options along with less command. For example, if you want to see line number with less then, type as below:

less -N filename

When less exits, the content of a file will be cleared from the screen. To keep content on the screen use -x option:

less -X filename

The most useful option is +F. Mostly, this is used to view the changes in file content, like log file.

less +F /var/log/auth.log

Less Commands#

The less program provides number of commands to search and navigate to entire file content. You can get list of all command just by typing h.

Following are the most common used commands to navigate in file content while use less:

CommandDescription
Space bar or fMove Forward one page.
Down arrow, Enter, e, or jMove forward one line.
Up arrow,y or kMove backward one line.
bMove Backward one page.
/patternSearch forward for matching patterns.
?patternSearch backward for matching patterns.
NRepeat previous search in reverse direction.
nRepeat previous search.
gGo to the first line in the file.
NgGo to the N-th line in the file.
GGo to the last line in the file.
pGo to the beginning of fthe ile.
NpGo to N percent into file.
hDisplay help.
qExit less.

Conclusion#

You have explain how to use the less command in Linux. If you have any query or suggestion, feel free to comment below.

If our content helps you, please consider buying us a coffee

Thank you for your support.

Share On
Share on Facebook
Share on Twitter
Share on Reddit
Share on Tumblr
 Previous Article How to Install GO on Debian 10 Linux
Next Article   How to Install Nginx on CentOS 8

Related Posts

  • How to Install SSH Keys on Ubuntu 22.04

    How to Set up SSH Keys on Ubuntu 22.04

    January 7, 2023
  • How to Install Fail2ban on Ubuntu 22.04

    How to Install and Configure Fail2ban on Ubuntu 22.04

    December 5, 2022
  • How to Enable SSH on Ubuntu 22.04

    How to Enable SSH on Ubuntu 22.04

    December 1, 2022

Leave a Reply Cancel reply

DigitalOcean Referral Badge

Popular Posts

  • How to Install Microsoft Edge Browser on Ubuntu 22.04
    How to Install Microsoft Edge Browser on Ubuntu 22.04 March 14, 2023
  • How to Install Ruby on Ubuntu 22.04 LTS
    How to Install Ruby on Ubuntu 22.04 LTS February 27, 2023
  • How to Install LEMP Stack on Ubuntu 22.04
    How to Install LEMP Stack on Ubuntu 22.04 March 18, 2023
  • How to Install Set Up Apache Virtual Hosts on Ubuntu 22.04
    How to Set Up Apache Virtual Hosts on Ubuntu 22.04 March 2, 2023
  • How to Install MariaDB on Debian 11 Bullseye
    How to Install MariaDB on Debian 11 Bullseye March 8, 2023
© 2020 TecNStuff All rights reserved. This website is using and storing cookies on your browser. By using this website you agree our Privacy Policy.  Follow us -  Twitter | Facebook