[Previous] [Contents] [Next]

less

Interactive paginator (UNIX)

Syntax:

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...]

Options:

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.

-?
Display a summary of the commands accepted by less (the same as the h command). If this option is given, all other options are ignored, and less exits after the help screen is viewed. (Depending on how your shell interprets the question mark, it may be necessary to quote the question mark, as follows: -\?)
-a
Start searches after the last line displayed on the screen, thus skipping all lines displayed on the screen. By default, searches begin at the second line on the screen (or after the last found line; see the -j option).
-b n
Use a nonstandard number of buffers. Buffers are 1K, and by default 10 buffers are used (except if data is coming from standard input; see the -B option). The number n specifies the number of buffers to use.
-B
Disable automatic allocation of buffers, so that only the default number of buffers is used. If more data is read than will fit in the buffers, the oldest data is discarded. By default, when data is coming from standard input, buffers are allocated automatically as needed to avoid loss of data.
-c
Do fullscreen redraws from the top line down. By default, fullscreen redraws are done by scrolling from the bottom of the screen.
-C
Clear the screen, then do fullscreen redraws from the top line down. By default, fullscreen redraws are done by scrolling from the bottom of the screen.
-d
Suppress the error message normally displayed if the terminal is dumb (i.e. lacks some important capability, such as the ability to clear the screen or scroll backward). The -d option does not otherwise change the behavior of less on a dumb terminal.
-e
Automatically exit the second time end-of-file is reached. By default, the only way to exit less is via the q command.
-E
Automatically exit the first time end-of-file is reached. By default, the only way to exit less is via the q command.
-f
Force nonregular files to be opened (a nonregular file is a directory or a device special file). Also, suppress the warning message when a binary file is opened. By default, less will refuse to open nonregular files.
-h n
Don't scroll backward any more than n lines. If it's necessary to scroll backward more than n lines, the screen is redrawn in a forward direction instead. (If the terminal can't scroll backward, -h 0 is implied.)
-i
Ignore case; uppercase and lowercase are considered identical. Also, text that is overstruck or underlined can be searched for. This option is ignored if any uppercase letters appear in the search pattern.
-j n
Use this line on the screen to position "target" lines. Target lines are the object of text searches, tag searches, jumps to a line number, jumps to a file percentage, and jumps to a marked position. The screen line is specified by a number: the top line on the screen is 1, the next is 2, and so on. The number may be negative to specify a line relative to the bottom of the screen: the bottom line on the screen is -1 (the number one), the second to the bottom is -2, and so on. With the -j option, searches begin at the line immediately after the target line. For example, if -j4 is used, the target line is the fourth line on the screen, so searches begin at the fifth line on the screen.
-m
Prompt verbosely (like more), with the percent into the file. By default, less prompts with a colon.
-M
Prompt even more verbosely than more.
-n
Suppress line numbers. The default (to use line numbers) may cause less to run more slowly in some cases, especially with a very large input file. Suppressing line numbers with -n will avoid this problem. Using line numbers means: the line number will be displayed in the verbose prompt and in the = command; the v command will pass the current line number to the editor.
-N
Display a line number at the beginning of each line.
-o file
Copy input to the named file as it is being viewed. This applies only when the input file is a pipe, not an ordinary file. If the file already exists, less will ask for confirmation before overwriting it.
-O file
Copy input to the named file as it is being viewed. This applies only when the input file is a pipe, not an ordinary file. If the file already exists, less will NOT ask for confirmation before overwriting it.

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.

-p pattern
Start at the first occurrence of pattern in the file. The -p option on the command line is equivalent to specifying +/pattern.
-q
Be moderately quiet; don't ring the terminal bell if an attempt is made to scroll past the end of the file or before the beginning of the file. If the terminal has a "visual bell," it is used instead. The bell will be rung on certain other errors, such as typing an invalid character. The default is to ring the terminal bell in all such cases.
-Q
Be totally quiet; never ring the terminal bell.
-r
Display "raw" control characters. The default is to display control characters using the caret (^) notation. For example, a Ctrl-A (001 octal) is displayed as ^A.

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.

-s
Squeeze consecutive blank lines into a single blank line.
-S
Chop rather than fold lines longer than the screen width. That is, the remainder of a long line is simply discarded. The default is to fold long lines; that is, display the remainder on the next and subsequent lines.
-t tag
Edit the file containing the specified tag. For this to work, there must be a file called tags in the current directory. (See ctags.)
-T tagsfile
Use the specified tags file in place of the tags file.
-u
Treat backspaces and carriage returns as printable characters (i.e. they're sent to the terminal when they appear in the input).
-U
Treat backspaces and carriage returns as control characters (i.e. they're handled as specified by the -r option).

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.

-w
Use blank lines to represent lines past the end of the file. By default, a tilde (~) character is used.
-x n
Set tab stops every n positions (the default 8).
-y n
Specifies a maximum number of lines to scroll forward. If it's necessary to scroll forward more than n lines, the screen is repainted instead. The -c or -C option may be used to repaint from the top of the screen if desired. By default, any forward movement causes scrolling.
-[z] n
Change the default scrolling window size to n lines. The default is one screenful. The z and w commands can also be used to change the window size. Note that the z may be omitted (as in -n).
+cmd
If a command-line option begins with + (plus), the remainder of that option is taken to be an initial command to less. For example, +G tells less to start at the end of the file rather than the beginning; and +/xyz tells it to start at the first occurrence of "xyz" in the file.

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).

++cmd
If the option starts with two plus signs (++), the initial command applies to every file being viewed, not just the first one. The + command (described in the "Commands" section) may also be used to set or change an initial command for every file.
file
A pathname of an input file. If no file operands are specified, less uses the standard input. If a file operand is the dash character (-), the standard input is read at that point of the sequence.

Description:

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

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.

Note:

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:

!
Search for lines that do not match the pattern.
*
Search multiple files. That is, if the search reaches the end of the current file without finding a match, the search continues in the next file in the command-line list.
@
Begin the search at the first line of the first file in the command-line list, regardless of what is currently displayed on the screen or the settings of the -a or -j options.

Files:

/usr/local/lib/less.hlp
Help file for less's help command.

Environment variables:

COLUMNS
Sets the number of columns on the screen. Takes precedence over the number of columns specified by the TERM variable.
EDITOR
The name of the editor (used for the v command).
LESS
Flags that are passed to less automatically.
LESSEDIT
Editor prototype string (used for the v command).
LINES
Sets the number of lines on the screen. Takes precedence over the number of lines specified by the TERM variable.
SHELL
The shell used to execute the ! command, as well as to expand filenames.
TERM
The type of terminal on which less is being run.

Contributing author:

Mark Nudelman

Caveats:

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.

See also:

ctags, more, vi


[Previous] [Contents] [Next]