Interactive paginator (UNIX)
less [-[+]aBcCdeEfimMnNqQrsSuUw] [-b n] [-x n] [-[z] n] [-h n] [-j n] [-p pattern] [-y n] [-[oO] logfile] [-t tag] [-T tagsfile] [+cmd] [++cmd] [file...]
Most options may be changed while less is running, via the dash (-) command.
Options are also taken from the LESS environment variable. The environment variable is parsed before the command line, so command-line options override the LESS environment variable. If an option appears in the LESS environment variable, it can be reset to its default on the command line by using the two-character combination -+ at the beginning of the command line.
A dollar sign ($) may be used to signal the end of an option string. This is important only for options like -t which take a following string.
If no log file has been specified, the -o and -O options can be used from within less to specify a log file. Without a filename, they will simply report the name of the log file.
Note that when -r is used, less can't keep track of the actual appearance of the screen (since this depends on how the screen responds to each type of control character). Thus, various display problems may result, such as long lines being split in the wrong place.
By default, if neither -u nor -U is given, backspaces that appear adjacent to an underscore character are treated specially: the underlined text is displayed using the terminal's hardware underlining capability. Backspaces that appear between two identical characters are also treated specially: the overstruck text is printed using the terminal's hardware boldface capability. Other backspaces are deleted, along with the preceding character. Carriage returns immediately followed by a newline are deleted; other carriage returns are handled as specified by the -r option.
As a special case, +number acts like +numberg; that is, it starts the display at the specified line number (note, however, that this may be slow -- see the g command).
The less utility is a program similar to more, but less allows backward movement in the file as well as forward movement. The less utility uses the system terminal capability database, so it can run on a variety of terminals. There is limited support for hardcopy terminals (on a hardcopy terminal, lines that should be printed at the top of the screen are prefixed with up-arrow).
The less utility will display a screen full of information, then prompt for user input by displaying a : prompt at the bottom of the screen. Commands can then be entered from the keyboard.
Commands may be preceded by a decimal number, called n in the following descriptions. The number is used by some commands, as indicated.
Command: | Description: |
---|---|
h | Help: display a summary of these commands. If you forget all the other commands, remember this one. |
[n] spacebar or [n] f | Scroll forward n lines; default is one window (see the -z option). If n is more than the screen size, only the final screenful is displayed. |
[n] z | Like spacebar, but if n is specified, it becomes the new window size. |
[n] Enter | Scroll forward n lines; the default is 1. The entire n lines are displayed, even if n is more than the screen size. |
[n] d | Scroll forward (down) n lines; the default is 1/2 screen size. If n is specified, it becomes the new default for subsequent d and u commands. |
[n] b | Scroll backward n lines; the default is one window (see the -z option). If n is more than the screen size, only the final screenful is displayed. |
[n] w | Like b, but if n is specified, it becomes the new window size. |
[n] k | Scroll backward n lines; the default is 1. The entire n lines are displayed, even if n is more than the screen size. |
[n] u | Scroll backward (up) n lines; the default is 1/2 screen size. If n is specified, it becomes the new default for subsequent d and u commands. |
[n] r | Redraw the screen. |
[n] F | Scroll forward, and keep trying to read when the end of the file is reached. Normally this command would be used when already at the end of the file. It is a way to monitor the tail of a file which is growing while it is being viewed. (The behavior is similar to the tail -f command.) |
[n] g | Go to line n in the file; the default is 1 (beginning of file). (Note that this may be slow if n is large.) |
[n] G | Go to line n in the file; the default is the end of the file. Note that this may be slow if n is large, or if n isn't specified and standard input, rather than a file, is being read. |
[n] p | Go to a position n percent into the file. n should be between 0 and 100. This works if standard input is being read, but only if less has already read to the end of the file. This is always fast, but not always useful. |
[n] { | If a left brace ( { ) appears in the top line displayed on the screen, the { command will go to the matching right brace, which is positioned on the bottom line of the screen. If there is more than one left brace on the top line, a number n may be used to specify the nth brace on the line. |
[n] } | If a right brace ( } ) appears in the bottom line displayed on the screen, the } command will go to the matching left brace, which is positioned on the top line of the screen. If there is more than one right brace on the top line, a number n may be used to specify the nth brace on the line. |
[n] ( | Like {, but applies to parentheses rather than braces. |
[n] ) | Like }, but applies to parentheses rather than braces. |
[n] [ | Like {, but applies to square brackets rather than braces. |
[n] ] | Like }, but applies to square brackets rather than braces. |
Esc Ctrl-F charchar | Acts like {, but uses the two characters as open and close brackets, respectively. For example, ESC ^F <> could be used to go forward to the > which matches the < in the top displayed line. |
Esc Ctrl-B charchar | Acts like }, but uses the two characters as open and close brackets, respectively. For example, ESC ^B <> could be used to go backward to the < which matches the > in the bottom displayed line. |
mchar | Followed by any lowercase letter, marks the current position with that letter. |
'char | (single quote) Followed by any lowercase letter, returns to the position that was previously marked with that letter. Followed by another single quote, returns to the position at which the last "large" movement command was executed. Followed by a ^ or $, jumps to the beginning or end of the file respectively. Marks are preserved when a new file is examined, so the ' command can be used to switch between input files. |
[n] /pattern | Search forward in the file for the nth line
containing the pattern; n defaults to 1. The
pattern is a regular expression, as recognized by sed. The
search starts at the second line displayed (but see the
-a and -j options, which change this).
Certain characters are special if entered at the beginning of the pattern; see note at end of table. |
[n] ?pattern | Search backward in the file for the nth line
containing the pattern. The search starts at the line immediately
before the top line displayed.
Certain characters are special as in the / command; see note at end of table. |
[n]Esc /pattern | Same as /*. |
[n]Esc ?pattern | Same as ?*. |
[n] n | Repeat previous search, for nth line containing the last pattern. If the previous search was modified by !, the search is made for the nth line not containing the pattern. If the previous search was modified by *, the search continues in the next (or previous) file if not satisfied in the current file. There is no effect if the previous search was modified by @. |
[n] N | Repeat previous search, but in the reverse direction. |
Esc n | Repeat previous search, but crossing file boundaries. The effect is as if the previous search were modified by *. |
Esc N | Repeat previous search, but in the reverse direction and crossing file boundaries. |
:e [filename] | Examine a new file. If the filename is missing, the "current" file (see the :n and :p commands) from the list of files in the command line is re-examined. A percent sign (%) in the filename is replaced by the name of the current file. A pound sign (#) is replaced by the name of the previously examined file. The filename is inserted into the command-line list of files so that it can be seen by subsequent :n and :p commands. If the filename consists of several files, they are all inserted into the list of files and the first one is examined. |
E | Same as :e. |
[n] :n | Examine the next file (from the list of files given in the command line). If a number n is specified, the nth next file is examined. |
[n] :p | Examine the previous file in the command-line list. If a number n is specified, the nth previous file is examined. |
[n] :x | Examine the first file in the command-line list. If a number n is specified, the nth file in the list is examined. |
= | Print some information about the file being viewed, including its name and the line number and byte offset of the bottom line being displayed. If possible, this also prints the length of the file, the number of lines in the file, and the percentage of the file above the last displayed line. |
-char | Followed by one of the command-line option letters, this will change the setting of that option and print a message describing the new setting. If the option letter has a numeric value (such as -b or -h), or a string value (such as -P or -t), a new value may be entered after the option letter. If no new value is entered, a message describing the current setting is printed and nothing is changed. |
-+char | Followed by one of the command-line option letters, this will reset the option to its default setting and print a message describing the new setting. The -+X command does the same thing as -+X on the command line. This doesn't work for string-valued options. |
--char | Followed by one of the command-line option letters, this will reset the option to the opposite of its default setting and print a message describing the new setting. The --X command does the same thing as -X on the command line. This doesn't work for numeric or string-valued options. |
+cmd | Causes the specified cmd to be executed each time a new file is examined. For example, +G causes less to initially display each file starting at the end rather than the beginning. |
V | Print the version number of less being run. |
q | Exit less. |
v | Invoke an editor to edit the current file being viewed. The editor is taken from the environment variable EDITOR, or defaults to vedit. |
! shell_command | Invoke a shell to run the shell_command given.
A percent sign (%) in the command is replaced by the name
of the current file. A pound sign (#) is replaced by the
name of the previously examined file. !! repeats the last shell command. ! with no shell command simply invokes a shell. In all cases, the shell is taken from the environment variable SHELL, or defaults to sh. |
| m shell_command | m represents any mark letter. Pipes a section of the input file to the given shell command. The section of the file to be piped is between the current position and the position marked by the letter. m may also be ^ or $ to indicate beginning or end of file, respectively. If m is a dot (.) or newline, the current screen is piped. The current screen is the minimum amount piped in any case. |
Certain characters are special if entered at the beginning of the pattern for the / and ? commands; they modify the type of search rather than become part of the pattern:
|
Mark Nudelman
The = command reports the line number of the line at the top of the screen, but the byte and percent of the line at the bottom of the screen.
If the :e command is used to name more than one file and if one of the named files has been viewed previously, the new files may be entered into the list in an unexpected order.