Linux "less" Command Line Options and Examples
opposite of more

Less is a program similar to more (1), but it has many more features. Less does not have to read the entire input file before start‐ ing, so with large input files it starts up faster than text editors like vi (1). Less uses termcap (or terminfo on some systems), so it can run on a variety of terminals.


Usage:

less -?
less --help
less -V
less --version
less [-[+]aABcCdeEfFgGiIJKLmMnNqQrRsSuUVwWX~]
[-b space] [-h lines] [-j line] [-k keyfile]
[-{oO} logfile] [-p pattern] [-P prompt] [-t tag]
[-T tagsfile] [-x tab,...] [-y lines] [-[z] lines]
[-# shift] [+[+]cmd] [--] [filename]...
(See the OPTIONS section for alternate option syntax with long option names.)




Command Line Options:

-?
This option displays a summary of the commands accepted by less (the same as the h command). (Depending on how your shellinterprets the question mark, it may be necessary to quote the question mark, thus: "-\?".)
less -? ...
-a
By default, forward searches start at the top of the displayed screen and backwards searches start at the bottom of the dis‐played screen (except for repeated searches invoked by the n or N commands, which start after or before the "target" linerespectively; see the -j option for more about the target line). The -a option causes forward searches to instead start atthe bottom of the screen and backward searches to start at the top of the screen, thus skipping all lines displayed on thescreen.
less -a ...
-A
Causes all forward searches (not just non-repeated searches) to start just after the target line, and all backward searches tostart just before the target line. Thus, forward searches will skip part of the displayed screen (from the first line up toand including the target line). Similarly backwards searches will skip the displayed screen from the last line up to andincluding the target line. This was the default behavior in less versions prior to 441.
less -A ...
-bn
Specifies the amount of buffer space less will use for each file, in units of kilobytes (1024 bytes). By default 64 K of buf‐fer space is used for each file (unless the file is a pipe; see the -B option). The -b option specifies instead that n kilo‐bytes of buffer space should be used for each file. If n is -1, buffer space is unlimited; that is, the entire file can beread into memory.
less -bn ...
-B
By default, when data is read from a pipe, buffers are allocated automatically as needed. If a large amount of data is readfrom the pipe, this can cause a large amount of memory to be allocated. The -B option disables this automatic allocation ofbuffers for pipes, so that only 64 K (or the amount of space specified by the -b option) is used for the pipe. Warning: useof -B can result in erroneous display, since only the most recently viewed part of the piped data is kept in memory; any ear‐lier data is lost.
less -B ...
-c
Causes full screen repaints to be painted from the top line down. By default, full screen repaints are done by scrolling fromthe bottom of the screen.
less -c ...
-C
Same as -c, for compatibility with older versions of less.
less -C ...
-d
The -d option suppresses the error message normally displayed if the terminal is dumb; that is, lacks some important capabil‐ity, such as the ability to clear the screen or scroll backward. The -d option does not otherwise change the behavior of lesson a dumb terminal.
less -d ...
-Dxcolor
[MS-DOS only] Sets the color of the text displayed. x is a single character which selects the type of text whose color isbeing set: n=normal, s=standout, d=bold, u=underlined, k=blink. color is a pair of numbers separated by a period. The firstnumber selects the foreground color and the second selects the background color of the text. A single number N is the same asN.M, where M is the normal background color. x may also be a to toggle strict ANSI sequence rendering (SGR mode).
less -Dxcolor ...
-e
Causes less to automatically exit the second time it reaches end-of-file. By default, the only way to exit less is via the"q" command.
less -e ...
-E
Causes less to automatically exit the first time it reaches end-of-file.
less -E ...
-f
Forces non-regular files to be opened. (A non-regular file is a directory or a device special file.) Also suppresses thewarning message when a binary file is opened. By default, less will refuse to open non-regular files. Note that some operat‐ing systems will not allow directories to be read, even if -f is set.
less -f ...
-F
Causes less to automatically exit if the entire file can be displayed on the first screen.
less -F ...
-g
Normally, less will highlight ALL strings which match the last search command. The -g option changes this behavior to high‐light only the particular string which was found by the last search command. This can cause less to run somewhat faster thanthe default.
less -g ...
-G
The -G option suppresses all highlighting of strings found by search commands.
less -G ...
-hn
Specifies a maximum number of lines to scroll backward. If it is necessary to scroll backward more than n lines, the screenis repainted in a forward direction instead. (If the terminal does not have the ability to scroll backward, -h0 is implied.)
less -hn ...
-i
Causes searches to ignore case; that is, uppercase and lowercase are considered identical. This option is ignored if anyuppercase letters appear in the search pattern; in other words, if a pattern contains uppercase letters, then that search doesnot ignore case.
less -i ...
-I
Like -i, but searches ignore case even if the pattern contains uppercase letters.
less -I ...
-jn
Specifies a line on the screen where the "target" line is to be positioned. The target line is the line specified by any com‐mand to search for a pattern, jump to a line number, jump to a file percentage or jump to a tag. The screen line may be spec‐ified 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 linerelative to the bottom of the screen: the bottom line on the screen is -1, the second to the bottom is -2, and so on. Alter‐nately, the screen line may be specified as a fraction of the height of the screen, starting with a decimal point: .5 is inthe middle of the screen, .3 is three tenths down from the first line, and so on. If the line is specified as a fraction, theactual line number is recalculated if the terminal window is resized, so that the target line remains at the specified frac‐tion of the screen height. If any form of the -j option is used, repeated forward searches (invoked with "n" or "N") begin atthe line immediately after the target line, and repeated backward searches begin at the target line, unless changed by -a or
less -jn ...
-J
Displays a status column at the left edge of the screen. The status column shows the lines that matched the current search.The status column is also used if the -w or -W option is in effect.
less -J ...
-kfilename
Causes less to open and interpret the named file as a lesskey (1) file. Multiple -k options may be specified. If the LESSKEYor LESSKEY_SYSTEM environment variable is set, or if a lesskey file is found in a standard place (see KEY BINDINGS), it isalso used as a lesskey file.
less -kfilename ...
-K
Causes less to exit immediately (with status 2) when an interrupt character (usually ^C) is typed. Normally, an interruptcharacter causes less to stop whatever it is doing and return to its command prompt. Note that use of this option makes itimpossible to return to the command prompt from the "F" command.
less -K ...
-L
Ignore the LESSOPEN environment variable (see the INPUT PREPROCESSOR section below). This option can be set from within less,but it will apply only to files opened subsequently, not to the file which is currently open.
less -L ...
-m
Causes less to prompt verbosely (like more), with the percent into the file. By default, less prompts with a colon.
less -m ...
-M
Causes less to prompt even more verbosely than more.
less -M ...
-n
Suppresses line numbers. The default (to use line numbers) may cause less to run more slowly in some cases, especially with avery large input file. Suppressing line numbers with the -n option will avoid this problem. Using line numbers means: theline number will be displayed in the verbose prompt and in the = command, and the v command will pass the current line numberto the editor (see also the discussion of LESSEDIT in PROMPTS below).
less -n ...
-N
Causes a line number to be displayed at the beginning of each line in the display.
less -N ...
-ofilename
Causes less to copy its input to the named file as it is being viewed. This applies only when the input file is a pipe, notan ordinary file. If the file already exists, less will ask for confirmation before overwriting it.
less -ofilename ...
-Ofilename
The -O option is like -o, but it will overwrite an existing file without asking for confirmation.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. The "s" command is equivalent to specifying -o from within less.
less -Ofilename ...
-ppattern
The -p option on the command line is equivalent to specifying +/pattern; that is, it tells less to start at the first occur‐rence of pattern in the file.
less -ppattern ...
-Pprompt
Provides a way to tailor the three prompt styles to your own preference. This option would normally be put in the LESS envi‐ronment variable, rather than being typed in with each less command. Such an option must either be the last option in theLESS variable, or be terminated by a dollar sign.
less -Pprompt ...
-Ps
followed by a string changes the default (short) prompt to that string.
less -Ps ...
-Pm
changes the medium (-m) prompt.
less -Pm ...
-PM
changes the long (-M) prompt.
less -PM ...
-Ph
changes the prompt for the help screen.
less -Ph ...
-P
changes the message printed by the = command.
less -P ...
-q
Causes moderately "quiet" operation: the terminal bell is not rung if an attempt is made to scroll past the end of the file orbefore the beginning of the file. If the terminal has a "visual bell", it is used instead. The bell will be rung on certainother errors, such as typing an invalid character. The default is to ring the terminal bell in all such cases.
less -q ...
-Q
Causes totally "quiet" operation: the terminal bell is never rung.
less -Q ...
-r
Causes "raw" control characters to be displayed. The default is to display control characters using the caret notation; forexample, a control-A (octal 001) is displayed as "^A". Warning: when the -r option is used, less cannot keep track of theactual appearance of the screen (since this depends on how the screen responds to each type of control character). Thus, var‐ious display problems may result, such as long lines being split in the wrong place.
less -r ...
-R
Like -r, but only ANSI "color" escape sequences are output in "raw" form. Unlike -r, the screen appearance is maintained cor‐rectly in most cases. ANSI "color" escape sequences are sequences of the form:ESC [ ... mwhere the "..." is zero or more color specification characters For the purpose of keeping track of screen appearance, ANSIcolor escape sequences are assumed to not move the cursor. You can make less think that characters other than "m" can endANSI color escape sequences by setting the environment variable LESSANSIENDCHARS to the list of characters which can end acolor escape sequence. And you can make less think that characters other than the standard ones may appear between the ESCand the m by setting the environment variable LESSANSIMIDCHARS to the list of characters which can appear.
less -R ...
-s
Causes consecutive blank lines to be squeezed into a single blank line. This is useful when viewing nroff output.
less -s ...
-S
Causes lines longer than the screen width to be chopped (truncated) rather than wrapped. That is, the portion of a long linethat does not fit in the screen width is not shown. The default is to wrap long lines; that is, display the remainder on thenext line.
less -S ...
-ttag
The -t option, followed immediately by a TAG, will edit the file containing that tag. For this to work, tag information mustbe available; for example, there may be a file in the current directory called "tags", which was previously built by ctags (1)or an equivalent command. If the environment variable LESSGLOBALTAGS is set, it is taken to be the name of a command compati‐ble with global (1), and that command is executed to find the tag. (See http://www.gnu.org/software/global/global.html). The
less -ttag ...
-Ttagsfile
Specifies a tags file to be used instead of "tags".
less -Ttagsfile ...
-u
Causes backspaces and carriage returns to be treated as printable characters; that is, they are sent to the terminal when theyappear in the input.
less -u ...
-U
Causes backspaces, tabs and carriage returns to be treated as control characters; that is, they are handled as specified bythe -r option.By default, if neither -u nor -U is given, backspaces which appear adjacent to an underscore character are treated specially:the underlined text is displayed using the terminal's hardware underlining capability. Also, backspaces which appear betweentwo identical characters are treated specially: the overstruck text is printed using the terminal's hardware boldface capabil‐ity. Other backspaces are deleted, along with the preceding character. Carriage returns immediately followed by a newlineare deleted. Other carriage returns are handled as specified by the -r option. Text which is overstruck or underlined can besearched for if neither -u nor -U is in effect.
less -U ...
-V
Displays the version number of less.
less -V ...
-w
Temporarily highlights the first "new" line after a forward movement of a full page. The first "new" line is the line immedi‐ately following the line previously at the bottom of the screen. Also highlights the target line after a g or p command. Thehighlight is removed at the next command which causes movement. The entire line is highlighted, unless the -J option is ineffect, in which case only the status column is highlighted.
less -w ...
-W
Like -w, but temporarily highlights the first new line after any forward movement command larger than one line.
less -W ...
-xn,...
Sets tab stops. If only one n is specified, tab stops are set at multiples of n. If multiple values separated by commas arespecified, tab stops are set at those positions, and then continue with the same spacing as the last two. For example, -x9,17will set tabs at positions 9, 17, 25, 33, etc. The default for n is 8.
less -xn,... ...
-X
Disables sending the termcap initialization and deinitialization strings to the terminal. This is sometimes desirable if thedeinitialization string does something unnecessary, like clearing the screen.
less -X ...
-yn
Specifies a maximum number of lines to scroll forward. If it is necessary to scroll forward more than n lines, the screen isrepainted instead. The -c or -C option may be used to repaint from the top of the screen if desired. By default, any forwardmovement causes scrolling.
less -yn ...
-[z]n
Changes the default scrolling window size to n lines. The default is one screenful. The z and w commands can also be used tochange the window size. The "z" may be omitted for compatibility with some versions of more. If the number n is negative, itindicates n lines less than the current screen size. For example, if the screen is 24 lines, -z-4 sets the scrolling windowto 20 lines. If the screen is resized to 40 lines, the scrolling window automatically changes to 36 lines.
less -[z]n ...
-"cc
Changes the filename quoting character. This may be necessary if you are trying to name a file which contains both spaces andquote characters. Followed by a single character, this changes the quote character to that character. Filenames containing aspace should then be surrounded by that character rather than by double quotes. Followed by two characters, changes the openquote to the first character, and the close quote to the second character. Filenames containing a space should then be pre‐ceded by the open quote character and followed by the close quote character. Note that even after the quote characters arechanged, this option remains -" (a dash followed by a double quote).
less -"cc ...
-~
Normally lines after end of file are displayed as a single tilde (~). This option causes lines after end of file to be dis‐played as blank lines.
less -~ ...
-#
Specifies the default number of positions to scroll horizontally in the RIGHTARROW and LEFTARROW commands. If the numberspecified is zero, it sets the default number of positions to one half of the screen width. Alternately, the number may bespecified as a fraction of the width of the screen, starting with a decimal point: .5 is half of the screen width, .3 is threetenths of the screen width, and so on. If the number is specified as a fraction, the actual number of scroll positions isrecalculated if the terminal window is resized, so that the actual scroll remains at the specified fraction of the screenwidth.
less -# ...
--follow-name
Normally, if the input file is renamed while an F command is executing, less will continue to display the contents of theoriginal file despite its name change. If --follow-name is specified, during an F command less will periodically attempt toreopen the file by name. If the reopen succeeds and the file is a different file from the original (which means that a newfile has been created with the same name as the original (now renamed) file), less will display the contents of that new file.
less --follow-name ...
--no-keypad
Disables sending the keypad initialization and deinitialization strings to the terminal. This is sometimes useful if the key‐pad strings make the numeric keypad behave in an undesirable manner.
less --no-keypad ...
--use-backslash
This option changes the interpretations of options which follow this one. After the --use-backslash option, any backslash inan option string is removed and the following character is taken literally. This allows a dollar sign to be included inoption strings.
less --use-backslash ...
-k
use of lesskey files
less -k ...
-t
metacharacters in filenames, such as *filename completion (TAB, ^L)Less can also be compiled to be permanently in "secure" mode.COMPATIBILITY WITH MOREIf the environment variable LESS_IS_MORE is set to 1, or if the program is invoked via a file link named "more", less behaves(mostly) in conformance with the POSIX "more" command specification. In this mode, less behaves differently in these ways:The -e option works differently. If the -e option is not set, less behaves as if the -e option were set. If the -e option is set,less behaves as if the -E option were set.The -m option works differently. If the -m option is not set, the medium prompt is used, and it is prefixed with the string
less -t ...
--More--".
The -n option acts like the -z option. The normal behavior of the -n option is unavailable in this mode.The parameter to the -p option is taken to be a less command rather than a search pattern.The LESS environment variable is ignored, and the MORE environment variable is used in its place.ENVIRONMENT VARIABLESEnvironment variables may be specified either in the system environment as usual, or in a lesskey (1) file. If environment variablesare defined in more than one place, variables defined in a local lesskey file take precedence over variables defined in the systemenvironment, which take precedence over variables defined in the system-wide lesskey file.COLUMNSSets the number of columns on the screen. Takes precedence over the number of columns specified by the TERM variable. (Butif you have a windowing system which supports TIOCGWINSZ or WIOCGETD, the window system's idea of the screen size takes prece‐dence over the LINES and COLUMNS environment variables.)EDITOR The name of the editor (used for the v command).HOME Name of the user's home directory (used to find a lesskey file on Unix and OS/2 systems).HOMEDRIVE, HOMEPATHConcatenation of the HOMEDRIVE and HOMEPATH environment variables is the name of the user's home directory if the HOME vari‐able is not set (only in the Windows version).INIT Name of the user's init directory (used to find a lesskey file on OS/2 systems).LANG Language for determining the character set.LC_CTYPELanguage for determining the character set.LESS Options which are passed to less automatically.LESSANSIENDCHARSCharacters which may end an ANSI color escape sequence (default "m").LESSANSIMIDCHARSCharacters which may appear between the ESC character and the end character in an ANSI color escape sequence (default"0123456789:;[?!"'#%()*+ ".LESSBINFMTFormat for displaying non-printable, non-control characters.LESSCHARDEFDefines a character set.LESSCHARSETSelects a predefined character set.LESSCLOSECommand line to invoke the (optional) input-postprocessor.LESSECHOName of the lessecho program (default "lessecho"). The lessecho program is needed to expand metacharacters, such as * and ?,in filenames on Unix systems.LESSEDITEditor prototype string (used for the v command). See discussion under PROMPTS.LESSGLOBALTAGSName of the command used by the -t option to find global tags. Normally should be set to "global" if your system has theglobal (1) command. If not set, global tags are not used.LESSHISTFILEName of the history file used to remember search commands and shell commands between invocations of less. If set to "-" or"/dev/null", a history file is not used. The default is "$HOME/.lesshst" on Unix systems, "$HOME/_lesshst" on DOS and Windowssystems, or "$HOME/lesshst.ini" or "$INIT/lesshst.ini" on OS/2 systems.LESSHISTSIZEThe maximum number of commands to save in the history file. The default is 100.LESSKEYName of the default lesskey(1) file.LESSKEY_SYSTEMName of the default system-wide lesskey(1) file.LESSMETACHARSList of characters which are considered "metacharacters" by the shell.LESSMETAESCAPEPrefix which less will add before each metacharacter in a command sent to the shell. If LESSMETAESCAPE is an empty string,commands containing metacharacters will not be passed to the shell.LESSOPENCommand line to invoke the (optional) input-preprocessor.LESSSECURERuns less in "secure" mode. See discussion under SECURITY.LESSSEPARATORString to be appended to a directory name in filename completion.LESSUTFBINFMTFormat for displaying non-printable Unicode code points.LESS_IS_MOREEmulate the more (1) command.LINES Sets the number of lines on the screen. Takes precedence over the number of lines specified by the TERM variable. (But ifyou have a windowing system which supports TIOCGWINSZ or WIOCGETD, the window system's idea of the screen size takes prece‐dence over the LINES and COLUMNS environment variables.)MORE Options which are passed to less automatically when running in more compatible mode.PATH User's search path (used to find a lesskey file on MS-DOS and OS/2 systems).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.VISUAL The name of the editor (used for the v command).
less --More--". ...