less
View contents of text files, one page
TLDR
Open a file
Page down/up
Go to end/start of file
Forward search for a string (press
Backward search for a string (press
Follow the output of the currently opened file
Open the current file in an editor
Exit
SYNOPSIS
less [options] [file ...]
or
command | less
PARAMETERS
-E
Causes less to automatically exit when it reaches the end of the file.
-F
Causes less to automatically exit if the entire file can be displayed on the first screen.
-i
Performs case-insensitive searches, unless the search pattern contains uppercase letters.
-N
Displays a line number at the beginning of each line.
-R
Outputs "raw" control characters. Useful for viewing files with ANSI color codes.
-S
Chops long lines instead of wrapping them. Lines longer than the screen width will be truncated.
-X
Disables the sending of termcap init/deinit strings to the terminal, which can prevent screen clearing after less exits.
-? or --help
Displays a summary of less commands and options.
DESCRIPTION
less is a command-line utility used to view the contents of a text file or output from a pipe, one screen at a time. Unlike its predecessor more, less allows for both forward and backward navigation through the file. It loads only the necessary portions of the file, making it highly efficient for very large files. It's the default pager for man pages and offers powerful search capabilities, line numbering, and customizable display options, making it an indispensable tool for system administrators and developers.
CAVEATS
less is a viewer, not an editor. While it offers powerful navigation and search, it does not allow modification of the file content.
INTERACTIVE KEYBINDINGS
less provides a rich set of interactive commands for navigation and searching once a file is open.
- q or Q: Exit less.
- Space or f: Scroll forward one window.
- b: Scroll backward one window.
- g: Go to the beginning of the file.
- G: Go to the end of the file.
- /pattern: Search forward for the specified pattern.
- ?pattern: Search backward for the specified pattern.
- n: Repeat the last search in the same direction.
- N: Repeat the last search in the opposite direction.
- h: Display the help screen with a list of all commands.
HISTORY
less was created by Mark Nudelman in the late 1980s as an improvement over the more command. The primary motivation was to enable backward scrolling and searching, which more lacked. Its name is a playful pun on more, implying it's "more" capable than more. It has since become the standard pager on most Unix-like systems, widely appreciated for its efficiency and flexibility.