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 more Command: View Text One Screen at a Time

Linux more Command: View Text One Screen at a Time

Learn how to use Linux more to read text one screen at a time, move and search interactively, start at a line or pattern, and choose between more and less.

Linux dnf Command: Manage RPM Distribution Packages

Linux dnf Command: Manage RPM Distribution Packages

Learn how to manage RPM Distribution Packages with the Linux dnf command, including practical examples, key options, and important precautions.

Linux last Command: Review Login and Reboot History

Linux last Command: Review Login and Reboot History

Learn how to use the Linux last command to review user login sessions, system reboots, and shutdown history, with essential options, practical examples, output interpretation, and common troubleshooting tips.

Linux rsync Command: Synchronize Files and Directories

Linux rsync Command: Synchronize Files and Directories

Learn how to synchronize Files and Directories with the Linux rsync command, including practical examples, key options, and important precautions.

Linux who Command: List Logged-In Users

Linux who Command: List Logged-In Users

Learn how to list Logged-In Users with the Linux who command, including practical examples, key options, and important precautions.

Linux cd Command: Change the Current Directory

Linux cd Command: Change the Current Directory

Learn how to use the Linux cd command to move between directories using absolute, relative, home, and previous paths, with essential options, practical examples, output interpretation, and common troubleshooting tips.

Linux whereis Command: Locate Binaries, Source, and Man Pages

Linux whereis Command: Locate Binaries, Source, and Man Pages

Learn how Linux whereis locates binaries, source files, and manual pages, limits each search type, lists effective paths, and differs from which and find.

Linux ps Command: Inspect Running Processes

Linux ps Command: Inspect Running Processes

Learn how to inspect Running Processes with the Linux ps command, including practical examples, key options, and important precautions.

Linux passwd Command: Change a User Password

Linux passwd Command: Change a User Password

Learn how to change a User Password with the Linux passwd command, including practical examples, key options, and important precautions.

Linux wc Command: Count Lines, Words, Characters, and Bytes

Linux wc Command: Count Lines, Words, Characters, and Bytes

Learn how to use the Linux wc command to count lines, words, characters, and bytes in files or standard input, with essential options, practical examples, output interpretation, and common troubleshooting tips.