# How To Use The Less Command In Linux

**URL:** <https://onehack.st/t/how-to-use-the-less-command-in-linux/217634>\
**Category:** Tutorials & Methods\
**Tags:** programming, tips-tricks\
**Created:** [March 31, 2022, 9:43am UTC](https://onehack.st/t/how-to-use-the-less-command-in-linux/217634 "2022-03-31T09:43:00Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![TheStrength](https://onehack.st/user_avatar/onehack.st/thestrength/32/46753_2.png) [@TheStrength](https://onehack.st/u/TheStrength)\
**Post date:** [March 31, 2022, 9:43am UTC](https://onehack.st/t/how-to-use-the-less-command-in-linux/217634/1 "2022-03-31T09:43:00Z")

</div>

This command works similarly tail in which it can be used to view content of files, except you can also scroll up or down of the file, or jump to specific line with some shortcut keys.

General syntax for `less` command:

`$ ` `less` `[FILE]`

##### Display line numbers

`less` `-N [` `file` `]`

The `-N` option allows you to see line numbers in the output of the less command.

**Example:** Using this option with the _ExampleFile.txt_.

 ![image](https://onehack.st/uploads/default/original/3X/4/d/4d63f82d366021c385e59dcf62a21db8cfad5f00.jpeg)

##### Search for text in a file

`less` `-p [word] [filename]`

This command helps you find a word or phrase in a file.

**Example:** Searching for the word _“example”_ in the _Example.txt_

 ![image](https://onehack.st/uploads/default/original/3X/d/a/da37c8b96d7cf54bcc15d3cfbc14b39548505714.jpeg)

##### Display multiple files

`less` `[file1] [file2] [file3]`

Use this command to open multiple files by typing the input file names one by one.

**Example:** Let’s display several files at once named _name1.txt_, _name2.txt_, _name3.txt_.

 ![image](https://onehack.st/uploads/default/original/3X/7/5/751eb7e351e6bb6ae08c4c76f13f857c55426f6e.jpeg)

##### Reduce blank lines

`less` `-s [filename]`

This option reduces a series of blanks lines and replaces them with a single blank line.

**Example:** There are a couple of consecutive blank lines in the _randomtext.txt_ file, let’s see how `less` handles them with the `-s` option.

 ![image](https://onehack.st/uploads/default/original/3X/6/9/6929e178f0f24ff58ea2ed008f3cbb9db112ccd8.jpeg)

##### Keep content in terminal after exit

`less` `-X [` `file` `]`

By default, when you exit `less`, the contents of the file will be removed from the screen. To keep them on the screen, use the `-X` option.

**Example:** Leaving the contents of the _sometext.txt_ file in the terminal.

 ![image](https://onehack.st/uploads/default/original/3X/f/b/fbde081efd68df9dbb2111f35eb918e94647ad5c.jpeg)

**Happy learning!**
