Skip to content

How to Use head Command

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. It 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, use the following command:

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`` Set a mark, which saves your current position. Enter a single character in place of to label the mark with that character.
’`` Return to a mark, where is the single character label for the mark. Note that ’ is the single-quote.
q Quit less
Feedback