What is Less?
Have you ever tried to read the manual of any command and got a lot of text and scroll back to the top page to read from the beginning right.
Less command helps you in such a situation. It simply displays the amount of text visible to your screen in one page at a time in your terminal, and then you have to scroll down to read further using the down arrow key on your keyboard.
Less command is handy to read file content or command output, producing many lines of output in the terminal. And you don’t have to install it externally. It comes preinstalled with all Linux distribution.
To read the file content using less command.
$ less file_destination
To view the output of any command with less. In this example, we are trying to read the manual of the dmidecode command using less command.
$ man dmidecode | less
Search navigation keys helps you to navigate between your output content easily.
- To go down or forward in your open output, you can use Down Arrow or Ctrl + n.
- To go up or backward in your open output, you can use Up Arrow or Ctrl + p.
If you want to navigate a particular string or pattern, you can simply use / and provide the string or pattern you want to search. Example: /<string>
If you want to navigate line by line instead of a bunch of paragraphs at one time, use j to go forward by one line and k to go backward by one line.
Output with Line Number
Suppose you want your output to come with a line number along with just a simple output.
Use -N along with less command to display line number in the output.
Open File with Line Number
$ less -N file_destination
Open Command Output with Line Number
$ <command> | less -N
Navigate using Line Number
If you directly want to navigate to a certain line using less command, you can do that to.
- 5j: 5 lines forward
- 5k: 5 lines backward
To exit or get out from the less command, simply use q or ZZ to exit.
I hope you really enjoyed how helpful and rich full less command is. If you have any questions related to less command, feel free to ask in the comment section.
Innovative tech mind with 10 years of experience working as a computer programmer, web developer, and security researcher. Capable of working with a variety of technology and software solutions, and managing databases.