Linux less Command: Browse and Search Long Text Files

The less command is an interactive pager for reading long text. It supports forward and backward navigation, searches, line jumps, and efficient access without first dumping the entire file to the terminal.

This guide explains the basic syntax, key options, practical examples, related commands, common cautions, and frequently asked questions for less.

What Is the less Command?

It displays a file or standard input in a full-screen terminal interface without changing the source. Navigation uses keys inside the pager, and q exits. Exact options and key bindings can vary with the installed less version and local configuration.

Basic Syntax

less [OPTION]... [FILE]...

Options and edge cases can vary by implementation and version. Check less --help and man less on the target system before relying on implementation-specific behavior.

Basic less Usage

Open and navigate a file

Space advances one screen, b moves back one screen, arrow keys move by lines, and g or G jumps to the beginning or end.

less system.log

Search inside the pager

Type /pattern to search forward or ?pattern to search backward. Use n and N to repeat in the same or opposite direction.

less /var/log/messages

Page through command output

Pipe a long output stream to less. Color preservation may require options on both the producing command and the pager.

journalctl -b | less

Screen visible when executed

less sample.txt displays the contents of a file one page at a time. Unlike typical standard output blocks, it does not print all at once but waits for key input.

less sample.txt

When you reach the end of the file, (END) may appear at the bottom of the screen. Space moves to the next screen, b moves to the previous screen, /word searches, and q exits. The status line and colors vary depending on settings and the terminal.

Key Options

Option Purpose
-N Display line numbers.
-S Chop long lines instead of wrapping them.
-i Ignore case in searches that contain only lowercase letters.
-I Always ignore case in searches.
-R Render selected ANSI color escape sequences.
+F Start in follow mode at the end of the file.

Practical Examples

Inspect numbered lines without wrapping

This combination is useful for wide logs or tabular data.

less -NS access.log

Follow new log entries

In follow mode, press Ctrl+C to return to normal navigation and search older content.

less +F application.log

Keep trusted color output

Use -R for selected color sequences and avoid broader raw-control modes for untrusted input.

grep --color=always -n 'failed' app.log | less -R

less and Related Commands

Command Primary role Best fit
less Bidirectional paging and search Long files and output
more Basic screen-by-screen paging Simple environments
cat Immediate complete output Short files
tail -f Continuous end-of-file tracking Live logs

Important Cautions

Pager keys are not shell commands

Commands such as /, g, and q are entered after less starts.

Do not broadly enable control sequences for untrusted text

Terminal escapes may have side effects; use the narrowest rendering mode that satisfies the task.

Log rotation can change what is followed

When a file is replaced during rotation, a service-aware log tool may track the intended stream more reliably.

FAQ

How do I quit less?

Press q.

How do I move to the next search match?

Press n; use N for the opposite direction.

How do I stop long lines from wrapping?

Start less with -S and use horizontal movement keys.

Does less load an entire large file into memory?

It is designed to access needed portions efficiently, although some input types and features can require temporary storage.

Related Resources