Name

less [options] [files] — less

Synopsis

/usr/bin stdin stdout[9] - file -- opt --help --version

Use less to view text one page at a time (or one window or screenful at a time). It’s great for text files, or as the final command in a shell pipeline with lengthy output.

$ command1 | command2 | command3 | command4 | less

While running less, type h for a help message describing all its features. Here are some useful keystrokes for paging through files.

Keystroke

Meaning

h, H

View a help page.

Spacebar, f, ^V, ^F

Move forward one screenful.

Enter

Move forward one line.

b, ^B, ESC-b

Move backward one screenful.

/

Enter search mode. Follow it with a regular expression and press Enter, and less will look for the first line matching it.

?

Same as /, but it searches backward in the file.

n

Repeat your most recent search forward.

N

Repeat your most recent search backward.

v

Edit the current file with your default text editor (the value of environment variable VISUAL, or if not defined, EDITOR, or if not defined, vi.

<

Jump to beginning of file.

>

Jump to end of file.

:n

Jump to next file.

:p

Jump to previous file.

less has a mind-boggling number of features; we’re presenting only the most common. The manpage is recommended reading.

Useful options

-c

Clear the screen before displaying the next page.

-m

Print a more verbose prompt, displaying the percentage of the file displayed so far.

-N

Prepend line numbers to the output.

-r

Display control characters literally; normally less converts them to a human-readable format.

-s

Squeeze ...

Get Linux Pocket Guide now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.