How to Use the Less Command

Updated by Nathan Melehan Written by Nathan Melehan

Contribute on GitHub

Report an Issue | View File | Edit File

What is Less?

On Linux systems, less is a command that displays file contents or command output one page at a time in your terminal. less is most useful for viewing the content of large files or the results of commands that produce many lines of output. The content displayed by less can be navigated by entering keyboard shortcuts.

Invoking Less

To view the content of a file with less:

less your-file-name

To view the output of another command with less, redirect the output from that command using a pipe:

ps -ef | less

To see line numbers on each line, use the -N option:

less -N your-file-name

Keyboard Navigation in Less

Use the following key commands to navigate through content viewed by less:

Key command Action
down arrow key, enter, e, or j Move down one line.
up arrow key, y, or k Move up one line.
space bar Move down one page.
b Move up one page.
right arrow key Scroll horizontally to the right.
left arrow key Scroll horizontally to the left.
g Go to the first line.
G Go to the last line.
10g Go to the 10th line. Enter a different number to go to other lines.
50p or 50% Go to the line half-way through the output. Enter a different number to go to other percentage positions.
/search term Search forward from the current position for the search term string.
?search term Search backward from the current position for the search term string.
n When searching, go to the next occurrence.
N When searching, go to the previous occurrence.
m<c> Set a mark, which saves your current position. Enter a single character in place of <c> to label the mark with that character.
'<c> Return to a mark, where <c> is the single character label for the mark. Note that ' is the single-quote.
q Quit less

Join our Community

Find answers, ask questions, and help others.

This guide is published under a CC BY-ND 4.0 license.