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

More in This Category
Linux comm Command: Compare Two Sorted Files

Linux comm Command: Compare Two Sorted Files

Learn how to compare Two Sorted Files with the Linux comm command, including practical examples, key options, and important precautions.

Linux rpm Command: Inspect RPM Packages and the Installed Database

Linux rpm Command: Inspect RPM Packages and the Installed Database

Learn how to inspect RPM Packages and the Installed Database with the Linux rpm command, including practical examples, key options, and important precautions.

Linux rm Command: Remove Files and Directories Safely

Linux rm Command: Remove Files and Directories Safely

Learn how to remove files and directory trees with Linux rm, use interactive safeguards, limit recursive deletion, and avoid destructive path mistakes.

Linux curl Command: Make URL Requests and Inspect HTTP Responses

Linux curl Command: Make URL Requests and Inspect HTTP Responses

Learn how to make URL Requests and Inspect HTTP Responses with the Linux curl command, including practical examples, key options, and important precautions.

Linux mktemp Command: Create Secure Temporary Files and Directories

Linux mktemp Command: Create Secure Temporary Files and Directories

Learn how to create unpredictable temporary files and directories with Linux mktemp, use templates and TMPDIR, clean up with trap, and avoid unsafe dry runs.

Linux printenv Command: Print Environment Variable Values

Linux printenv Command: Print Environment Variable Values

Learn how to use the Linux printenv command to print all environment variables or selected variable values, with essential options, practical examples, output interpretation, and common troubleshooting tips.

Linux Tutorial / File Types and Metadata: ls, file, stat, and readlink

Linux Tutorial / File Types and Metadata: ls, file, stat, and readlink

Learn what ls, file, stat, and readlink each reveal about a Linux file, including type, size, timestamps, and symbolic-link targets.

Linux csplit Command: Split Files at Lines or Patterns

Linux csplit Command: Split Files at Lines or Patterns

Learn how to split Files at Lines or Patterns with the Linux csplit command, including practical examples, key options, and important precautions.

Linux Tutorial / Hard Links vs. Symbolic Links in Linux: Differences and Examples

Linux Tutorial / Hard Links vs. Symbolic Links in Linux: Differences and Examples

Compare hard and symbolic links through inode and path behavior, then create both kinds of link and observe what happens when the original name changes.

Linux touch Command: Create Files and Change Timestamps

Linux touch Command: Create Files and Change Timestamps

Learn how to use the Linux touch command to create empty files and change access or modification timestamps, including reference times, date formats, and symlink handling.