Linux commands
Browse topics

Reading long output with less

Version
unversioned
Review
Draft

Summary#

less shows text one screen at a time. It can move backward, search and follow a growing file without loading the whole file first.

Syntax#

sh
less /var/log/app.log
journalctl | less
less +F app.log
less -S table.csv
less -R colored.log
less +/ERROR app.log

Inside less, Space and b move by pages, /text and ?text search, n repeats the search, G goes to the end and q quits. +F follows new data until Ctrl+C. -S cuts long lines instead of wrapping them and -R shows color codes.

Example#

sh
(
  set -eu
  dir=$(mktemp -d)
  trap 'rm -rf -- "$dir"' EXIT
  printf '%s\n' alpha beta gamma > "$dir/words"

  less "$dir/words" | tail -n 2
)

Expected output#

When standard output is a pipe or a file, less copies the text without opening the pager.

Text
beta
gamma

Common mistakes#

Press q to leave; Ctrl+C only interrupts the current action, such as following a file. Searches are case-sensitive unless you start less with -i. Line numbers and jumping to the end can be slow on very large files; -n disables line numbering. Reading from a pipe, less keeps what it has read in memory, so paging through a very large stream can use a lot of it; save the output to a file first.

Version applicability#

This entry describes less 668. Option defaults can come from the LESS environment variable.

Sources#

Attribution
DevLookup contributors
License
CC-BY-4.0