less – Browse file content by flipping pages up and down in split screen

The less command is a Linux utility that allows users to view files in a terminal window. It is similar to the more command, but with additional features such as the ability to scroll up and down through a file, search for specific text, and view files in a split-screen mode.

Overview

To use the less command, simply type less followed by the name of the file you wish to view. For example, to view the contents of a file named example.txt, you would enter the following command:

less example.txt

Once the file is open, you can scroll up and down through the file using the arrow keys or the Page Up and Page Down keys. You can also use the Home key to go to the beginning of the file and the End key to go to the end of the file.

In addition to scrolling through the file, you can also search for specific text by typing a forward slash (/) followed by the text you wish to search for. For example, to search for the word “Linux” in the file, you would enter the following command:

/Linux

This will highlight the first occurrence of the word “Linux” in the file. To search for the next occurrence, simply press the n key.

less also has a split-screen mode that allows you to view two parts of the same file at the same time. To enter split-screen mode, press the letter S. This will split the screen in half, with the top half showing the current part of the file and the bottom half showing the rest of the file. You can then use the arrow keys or the Page Up and Page Down keys to scroll through each half of the file independently.

Options

The following table lists the available options for the less command:

Option Description
-N Displays line numbers
-S Truncates long lines
-i Ignores case when searching
-F Quits immediately if the file can be displayed on one screen
-R Displays raw control characters
-X Disables sending the termcap initialization and deinitialization strings
-h Displays a help screen

Troubleshooting tips

  • If you are unable to scroll through the file, make sure that you are not in search mode. Press the Esc key to exit search mode.
  • If the file is not displayed properly, try using the -R option to display raw control characters.
  • If you are having trouble finding a specific piece of text, make sure that you have spelled the text correctly and that it is present in the file.

Notes

  • less is a very powerful tool that can be used to quickly view and search through large files.
  • To exit less, simply press the q key.