Less (Unix)
Encyclopedia
less
is a terminal pagerTerminal pager
A terminal pager, or paging program, is a computer program used to view the contents of a text file moving down the file one line or one screen at a time. Some, but not all, pagers allow movement up a file. A popular cross-platform terminal pager is more. more can move forwards and backwards in...
program
Computer program
A computer program is a sequence of instructions written to perform a specified task with a computer. A computer requires programs to function, typically executing the program's instructions in a central processor. The program has an executable form that the computer can use directly to execute...
on Unix
Unix
Unix is a multitasking, multi-user computer operating system originally developed in 1969 by a group of AT&T employees at Bell Labs, including Ken Thompson, Dennis Ritchie, Brian Kernighan, Douglas McIlroy, and Joe Ossanna...
, Windows
Microsoft Windows
Microsoft Windows is a series of operating systems produced by Microsoft.Microsoft introduced an operating environment named Windows on November 20, 1985 as an add-on to MS-DOS in response to the growing interest in graphical user interfaces . Microsoft Windows came to dominate the world's personal...
, and Unix-like
Unix-like
A Unix-like operating system is one that behaves in a manner similar to a Unix system, while not necessarily conforming to or being certified to any version of the Single UNIX Specification....
systems used to view (but not change) the contents of a text file
Text file
A text file is a kind of computer file that is structured as a sequence of lines of electronic text. A text file exists within a computer file system...
one screen at a time. It is similar to more, but has the extended capability of allowing both forward and backward navigation through the file. Unlike most Unix text editors/viewers, less does not need to read the entire file before starting, resulting in faster load times with large files.
History
less was initially written by Mark Nudelman during 1983-85, in the need of a version of more able to do backward scrolling of the displayed text. The name came from the joke of doing "backwards more." To help remember the difference between less and more, a common joke is to say, "less > more," implying that less has greater functionality than more. A similar saying is that "less is more, more or less". less is now part of the GNUGNU
GNU is a Unix-like computer operating system developed by the GNU project, ultimately aiming to be a "complete Unix-compatible software system"...
project and it is included in most Unix systems.
Usage
less can be invoked with options to change its behaviour, for example, the number of lines to display on the screen. A few options vary depending on the operating system. While less is displaying the file, various commands can be used to navigate through the file. These commands are based on those used by both more and viVi
vi is a screen-oriented text editor originally created for the Unix operating system. The portable subset of the behavior of vi and programs based on it, and the ex editor language supported within these programs, is described by the Single Unix Specification and POSIX.The original code for vi...
. It is also possible to search for character patterns in the file.
By default, less displays the contents of the file to the standard output (one screen at a time). If the file name argument is omitted, it displays the contents from standard input (usually the output of another command through a pipe
Pipeline (Unix)
In Unix-like computer operating systems , a pipeline is the original software pipeline: a set of processes chained by their standard streams, so that the output of each process feeds directly as input to the next one. Each connection is implemented by an anonymous pipe...
). If the output is redirected to anything other than a terminal
Computer terminal
A computer terminal is an electronic or electromechanical hardware device that is used for entering data into, and displaying data from, a computer or a computing system...
, for example a pipe to another command, less behaves like cat
Cat (Unix)
The cat command is a standard Unix program used to concatenate and display files. The name is from catenate, a synonym of concatenate.- Specification :...
.
The command-syntax
Syntax
In linguistics, syntax is the study of the principles and rules for constructing phrases and sentences in natural languages....
is:
less [options] file_name
Frequently used options
-g
: Highlights just the current match of any searched string.-I
: Case-insensitive searches.-M
: Shows more detailed prompt, including file position.-N
: Shows line numbers (useful for source codeSource codeIn computer science, source code is text written using the format and syntax of the programming language that it is being written in. Such a language is specially designed to facilitate the work of computer programmers, who specify the actions to be performed by a computer mostly by writing source...
viewing).-S
: Disables line wrap ("chop long lines"). Long lines can be seen by side scrolling.-?
: Shows help.
Frequently used commands
- [Arrows]/[Page Up]/[Page Down]/[Home]/[End]: Navigation.
- [Space bar]: Next page.
- b: Previous page.
- ng: Jump to line number n. Default is the start of the file.
- nG: Jump to line number n. Default is the end of the file.
- /pattern: Search for pattern. Regular expressionRegular expressionIn computing, a regular expression provides a concise and flexible means for "matching" strings of text, such as particular characters, words, or patterns of characters. Abbreviations for "regular expression" include "regex" and "regexp"...
s can be used. [/ = slash] Press / and then Enter to repeat the previous search pattern. Press ESC and then u to undo search highlighting. - n: Go to next match (after a successful search).
- N: Go to previous match.
- mletter: Mark the current position with letter.
' letter: Return to position letter. [' = single quote]'^ or g: Go to start of file.'$ or G: Go to end of file.- s: Save current content (got from another program like grepGrepgrep is a command-line text-search utility originally written for Unix. The name comes from the ed command g/re/p...
) in a file. - = or Ctrl+g: File information.
- F: continually read information from file and follow its end. Useful for logs watching. Use Ctrl+c to exit this mode.
- -option: Toggle command-line option -option.
- h: Help.
- q: Quit.