less command in Linux (original) (raw)

Last Updated : 22 Jan, 2026

The less command in Linux is used to view the contents of a file one page at a time without opening it in an editor, making it ideal for reading large files efficiently.

Using 'less' with Pipelines

The less command can also be used in conjunction with other commands through pipelines. This allows us to view the output of a command directly in the less pager.

**Note: I'm using dmesg output as input to less command in the following examples.

**For Example:

If you want to read the contents of dmesg command, it's better to use it with fewer command

dmesg | less

**Output:

348

**Syntax:

less [options] filename

Examples of `less` command in Linux

Let's look at a few examples to illustrate the usage of the less command with different options.

1. Searching for a pattern

dmesg | less -p "fail"

The above command tells less to start at first occurrence of pattern "fail" in the file and displaying the file from that point.

**Output:

3492. Displaying line number

The -N option displays line numbers along with the file content, allowing you to reference specific lines easily.

dmesg | less -N

**Output:

3503. Checking a small file

The file `/home//Mandeep/test/first.erl` is small enough to fit on a single screen. The `-F` option causes less to exit immediately without displaying the file since it can be fully shown in one go.

**Command:

less -F /home/Mandeep/test/first.erl

Commonly Used Options in`less`command

Here are the most commonly used and practical options of the less command in Linux: