less: command not found

Both the less and more commands are similar in that they enable you to display the contents of a file and page through those contents if they extend beyond the screen. The less command typically has additional features that more doesn’t, but newer versions of more have added some of those features. While you’re free to use either command, the less command is generally preferred.

Syntax

The syntax of the less command is:

$ less [options] {file names}

less Command Options

The following table lists some of the options for the less command.

Option Description
-e Exit the program the second time it reaches the end of the file.
-E Exit the program the first time it reaches the end of the file.
-I Ignore case in searches.
-n Suppress line numbers.

If you encounter the below error while running the less command:

less: command not found

you may try installing the below package as per your choice of distribution:

Distribution Command
OS X brew install less
Debian apt-get install less
Ubuntu apt-get install less
Alpine apk add less
Arch Linux pacman -S less
Kali Linux apt-get install less
CentOS yum install less
Fedora dnf install less
Raspbian apt-get install less

less Command Examples

1. Open a file:

$ less source_file

2. Page down/up:

[Space] (down), b (up)

3. Go to end/start of file:

G (end), g (start)

4. Forward search for a string (press `n`/`N` to go to next/previous match):

/something

5. Backward search for a string (press `n`/`N` to go to next/previous match):

?something

6. Follow the output of the currently opened file:

F

7. Open the current file in an editor:

v

8. Exit from the less command:

q

Navigation in less command

Navigation in less uses many of the same commands you’ve seen before, like the arrow keys to scroll line-by-line and Page Up and Page Down to scroll by page. You can also use / to search a file for a particular text string, and press n and N to move to the next or previous instance of the searched string, respectively. Press q to quit the program.

Related Post