Viewing and processing text

Command less

View text page by page

Linux · Bash examples · commands run on the selected server

When to use less

Use less to inspect long files interactively without dumping them into the terminal. Search inside the viewer and quit back to the shell when finished; this is a viewing tool rather than a text editor.

Syntax

less [OPTIONS] FILE

Square brackets mark optional arguments; an ellipsis means repetition. Replace example file names, user names and server addresses with your own values.

Common options and arguments

-N
Show line numbers.
-S
Do not wrap long lines.
+F
Start in monitoring mode while appending a file.

Usage examples

Open log

less -N ./app.log

The log opens with line numbers for easier navigation.

Read wide table

less -S ./report.tsv

Long lines can be scrolled horizontally instead of wrapping.

Open command output

journalctl -u nginx --no-pager | less

Service journal output is passed to the pager after disabling the journal's own pager.

Notes and limitations

  • In the viewer, / starts the search, n repeats it, q closes the view.
  • In +F mode, first press Ctrl+C to go to normal viewing; then q.

Common questions and troubleshooting

How do I leave less or search within it?

Press q to quit. Type a slash followed by a search pattern and Enter, then use n for the next match.

Why does less behave differently in a script?

A pager expects an interactive terminal. For automation, use noninteractive filters and explicit output rather than waiting for keyboard input.

Further help

Options vary by version and distribution. Check the installed documentation with this command: man less.