LESS(1)

๐ŸŽ€ LESS(1) โ€” General Commands Manual ๐ŸŽ€

hiii so this is LESS(1), the General Commands Manual entry for everyone's favorite pager, and honestly? it's giving legend behavior. it's long, bestie โ€” like, 13-parts long โ€” but we're gonna get through it together. grab a snack. ๐Ÿ’–


โœจ NAME โœจ

less โ€” display the contents of a file in a terminal ๐Ÿฆ‹

๐Ÿ“œ SYNOPSIS ๐Ÿ“œ

       [-h lines] [-j line] [-k key-file] [-{o|O} log-file] [-p pattern]
       [-P prompt] [-t tag] [-T tags-file] [-x tab[{,tab}...]]
       [-y lines] [-z lines] [-lines] [-"cc] [-# shift] [+less-command]
       [--] [file ...]

less -?
less --help

less -V
less --version

also, real quick: (See the OPTIONS section for alternate option syntax with long option names.) โ€” so if the short flags aren't your vibe, there's a whole other way to spell them. screaming, crying, options. ๐Ÿ˜ญ

๐Ÿ’œ DESCRIPTION ๐Ÿ’œ

so like. Less is a program similar to more(1), except it has way more features โ€” like, it ate and left no crumbs. ๐Ÿฝ๏ธ

the iconic part? Less does not have to read the entire input file before starting, so with large input files it starts up faster than text editors like vi(1). speed demon behavior. ๐ŸŽ๏ธโœจ

Less uses termcap (or terminfo on some systems), so it can run on a variety of terminals โ€” she's adaptable, she's versatile, she's not gonna break on your weird setup. ๐Ÿ’… there is even limited support for hardcopy terminals. (On a hardcopy terminal, lines which should be printed at the top of the screen are prefixed with a caret.) quirky but valid.


๐Ÿ‘‘ COMMANDS ๐Ÿ‘‘

okay bestie this is the big one. the commands are based on both more and vi. iconic crossover event. ๐ŸŒˆ

Commands may be preceded by a decimal number, called N in the descriptions below. the number is used by some commands, as indicated. iykyk. ๐Ÿ”ข

also, super important vocab, no cap: in the following descriptions, ^X means control-X. ESC stands for the ESCAPE key; for example ESC-v means the two character sequence "ESCAPE", then "v". ๐Ÿซถ

  • h or H โ€” Help: display a summary of these commands. If you forget all the other commands, remember this one. fr fr, this is your emergency contact. ๐Ÿ“ž
  • SPACE or ^V or f or ^F โ€” Scroll forward N lines, default one window (see option -z below). If N is more than the screen size, only the final screenful is displayed. โš ๏ธ Warning: some systems use ^V as a special literalization character.
  • z โ€” Like SPACE, but if N is specified, it becomes the new window size. she's setting the rules now. ๐Ÿ‘‘
  • ENTER or RETURN or ^N or e or ^E or j or ^J โ€” Scroll forward N lines, default 1. The entire N lines are displayed, even if N is more than the screen size.
  • d or ^D โ€” Scroll forward N lines, default one half of the screen size. If N is specified, it becomes the new default for subsequent d and u commands.
  • b or ^B or ESC-v โ€” Scroll backward N lines, default one window (see option -z below). If N is more than the screen size, only the final screenful is displayed.
  • w โ€” Like ESC-v, but if N is specified, it becomes the new window size.
  • y or ^Y or ^P or k or ^K โ€” Scroll backward N lines, default 1. The entire N lines are displayed, even if N is more than the screen size. โš ๏ธ Warning: some systems use ^Y as a special job control character.
  • u or ^U โ€” Scroll backward N lines, default one half of the screen size. If N is specified, it becomes the new default for subsequent d and u commands.
  • J โ€” Like j, but continues to scroll beyond the end of the file. she does not know how to stop. ๐Ÿ’€
  • K or Y โ€” Like k, but continues to scroll beyond the beginning of the file.
  • ESC-SPACE โ€” Like SPACE, but scrolls a full screenful, even if it reaches the end of the file.
  • ESC-b โ€” Like b, but scrolls a full screenful, even if it reaches the beginning of the file.
  • ESC-j โ€” Scroll forward N file lines, default 1. A file line is a complete line in the file, terminated by a newline.
  • ESC-k โ€” Scroll backwards N file lines, default 1.
  • ESC-) or RIGHTARROW โ€” Scroll horizontally right N characters, default half the screen width (see the -# option). If a number N is specified, it becomes the default for future RIGHTARROW and LEFTARROW commands. While the text is scrolled, it acts as though the -S option (chop lines) were in effect.
  • ESC-] or ESC-RIGHTARROW โ€” Scroll horizontally right N characters like RIGHTARROW, but stop scrolling when the last (rightmost) character on the displayed screen becomes visible at the right margin. polite. considerate. ๐ŸŽ€
  • ESC-( or LEFTARROW โ€” Scroll horizontally left N characters, default half the screen width (see the -# option). If a number N is specified, it becomes the default for future RIGHTARROW and LEFTARROW commands.
  • ESC-} or ^RIGHTARROW or SHIFT-RIGHTARROW โ€” Scroll horizontally right to show the end of the longest displayed line.
  • ESC-{ or ^LEFTARROW or SHIFT-LEFTARROW โ€” Scroll horizontally left back to the first column.
  • ^END or SHIFT-END โ€” Go to line N in the file, default the end of the file, and scroll horizontally right to show the end of the longest displayed line.
  • ^HOME or SHIFT-HOME โ€” Go to line N in the file, default 1 (beginning of file), and scroll horizontally left back to the first column.
  • r or ^R or ^L โ€” Repaint the screen. โœจ glow up โœจ
  • R โ€” Repaint the screen, discarding any buffered input. That is, reload the current file. Useful if the file is changing while it is being viewed. she's refreshed, she's reborn. ๐Ÿฆ‹
  • F โ€” Scroll forward, and keep trying to read when the end of 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.) To stop waiting for more data, enter the interrupt character (usually ^C). On systems which support poll(2) you can also use ^X or the character specified by the --intr option. If the input is a pipe and the --exit-follow-on-close option is in effect, less will automatically stop waiting for data when the input side of the pipe is closed. ๐Ÿซถ the live-updating main character.
  • ESC-f โ€” Like F, but each time a line is found which matches the last search pattern, the terminal bell is rung. ๐Ÿ””
  • ESC-F โ€” Like F, but as soon as a line is found which matches the last search pattern, the terminal bell is rung and forward scrolling stops.
  • g or < or ESC-< or HOME โ€” Go to line N in the file, default 1 (beginning of file). (โš ๏ธ Warning: this may be slow if N is large.)
  • G or > or ESC-> or END โ€” Go to line N in the file, default the end of the file. (โš ๏ธ Warning: this may be slow if N is large, or if N is not specified and standard input, rather than a file, is being read.)
  • ESC-G โ€” Same as G, except if no number N is specified and the input is standard input, goes to the last line which is currently buffered.
  • p or % โ€” Go to a position N percent into the file. N should be between 0 and 100, and may contain a decimal point. mathematics, but make it cute. ๐Ÿ”ข
  • P โ€” Go to the line containing byte offset N in the file.
  • { โ€” If a left curly bracket appears in the top line displayed on the screen, the { command will go to the matching right curly bracket. The matching right curly bracket is positioned on the bottom line of the screen. If there is more than one left curly bracket on the top line, a number N may be used to specify the N-th bracket on the line.
  • } โ€” If a right curly bracket appears in the bottom line displayed on the screen, the } command will go to the matching left curly bracket. The matching left curly bracket is positioned on the top line of the screen. If there is more than one right curly bracket on the bottom line, a number N may be used to specify the N-th bracket on the line.
  • ( โ€” Like {, but applies to parentheses rather than curly brackets.
  • ) โ€” Like }, but applies to parentheses rather than curly brackets.
  • [ โ€” Like {, but applies to square brackets rather than curly brackets.
  • ] โ€” Like }, but applies to square brackets rather than curly brackets.
  • ESC-^F โ€” Followed by two characters, 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. bracket matching but you get to pick the brackets. custom. ๐Ÿ’…
  • ESC-^B โ€” Followed by two characters, 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.
  • m โ€” Followed by any lowercase or uppercase letter, marks the first displayed line with that letter. If a number N is given, line number N is marked instead. If the status column is enabled via the -J option, the status column shows the marked line. bookmarking, but superior. ๐Ÿ”–
  • M โ€” Acts like m, except the last displayed line is marked rather than the first displayed line. If a number N is given, line number N is marked instead.
  • ' โ€” (Single quote.) Followed by any lowercase or uppercase letter, returns to the position which 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. If a number N is given, the marked line is placed on the N-th line on the screen. Otherwise, it is placed on the same line that it was on when it was marked (the first line on the screen if marked via the m command, the last line on the screen if marked via the M command, or the line that was clicked if marked via the mouse). Marks are preserved when a new file is examined within a single invocation of less, so the ' command can be used to switch between input files. The --save-marks option causes marks to be preserved across different invocations of less. so many options bestie, she contains multitudes. ๐Ÿ˜ญ
  • ^X^X โ€” Same as single quote.
  • ESC-m โ€” Followed by any lowercase or uppercase letter, clears the mark identified by that letter. bye bye bookmark. ๐Ÿซถ
  • /pattern โ€” Search forward in the file for the N-th line containing the pattern. N defaults to 1. The pattern is a regular expression, as recognized by the regular expression library supplied by your system. By default, searching is case-sensitive (uppercase and lowercase are considered different); the -i option can be used to change this. The search starts at the first line displayed (but see the -a and -j options, which change this). ๐Ÿ”Ž she's looking for you.

Certain characters are special if entered at the beginning of the pattern; they modify the type of search rather than become part of the pattern:

  • ^N or ! โ€” Search for lines which do NOT match the pattern.
  • ^E or * โ€” the search-multiple-files modifier, bestie. If your search reaches the END of the current file without finding a match, it just keeps going into the next file in the command line list. ๐Ÿฆ‹
    • ^F or @ โ€” different energy entirely: this one says "start from the top." It begins the search at the first line of the FIRST file in the command line list, no matter what's currently displayed on your screen and no matter what the -a or -j options are set to. Iconic behavior only. ๐Ÿ‘‘
    • ^K โ€” KEEP your current position, queen. This highlights any text on the current screen that matches your pattern, but it does not move you to the first match. You stay exactly where you are. ๐Ÿ’…
    • ^R โ€” no regex today, we're doing it raw. This makes less not interpret regular expression metacharacters at all; instead it does a simple textual comparison. ๐Ÿ“
    • ^S โ€” followed by a digit N between 1 and 5. Only text which has a non-empty match for the N-th parenthesized SUB-PATTERN will be considered to match the pattern. Example time, because this one's a lil brain-bendy: searching for "(abc)|(def)" modified with ^S1 would search for instances of "abc", but would highlight instances of both "abc" and "def". (Supported only if less is built with one of the regular expression libraries posix, pcre, or pcre2.) And yes, you can stack multiple ^S modifiers, to match more than one sub-pattern. โœจ
    • ^W โ€” WRAP around the current file. That is, if the search reaches the end of the current file without finding a match, the search continues from the first line of the current file up to the line where it started. Heads up though: if the ^W modifier is set, the ^E modifier is ignored. ๐Ÿ˜ญ
    • ^L โ€” the literalizer, the "I said what I said" modifier. The next character is taken literally, meaning it becomes part of the pattern even if it's one of the search modifier characters listed above. ๐ŸŽ€

?pattern โ€” search backward in the file for the N-th line containing the pattern. The search starts at the last line displayed (but see the -a and -j options, which change this, bestie โ€” they always changing things).

Certain characters are special, exactly like in the / command:

  • ^N or ! โ€” search for lines which do NOT match the pattern. Reverse the vibes. ๐Ÿ™ˆ
  • ^E or * โ€” search multiple files. If the search reaches the beginning of the current file without finding a match, the search continues in the previous file in the command line list.
  • ^F or @ โ€” begin the search at the last line of the last file in the command line list, regardless of what is currently displayed on the screen or the settings of the -a or -j options. ๐ŸŒˆ
  • ^K โ€” same as in forward searches.
  • ^R โ€” same as in forward searches.
  • ^S โ€” same as in forward searches.
  • ^W โ€” WRAP around the current file. That is, if the search reaches the beginning of the current file without finding a match, the search continues from the last line of the current file up to the line where it started.
  • ^L โ€” same as in forward searches.

  • ESC-/pattern โ€” literally the same thing as /*. ๐Ÿ’–
  • ESC-?pattern โ€” literally the same thing as ?*. ๐Ÿ’–
  • n โ€” repeat the previous search, for the N-th line containing the last pattern. Important details tho: if the previous search was modified by ^N, the search is made for the N-th line NOT containing the pattern. If the previous search was modified by ^E, the search continues in the next (or previous) file if it's not satisfied in the current file. If the previous search was modified by ^R, the search is done without using regular expressions. If the previous search was modified by ^W, the search wraps at the end (or beginning) of the file. And there is no effect if the previous search was modified by ^F or ^K. ๐Ÿ’€
  • N โ€” repeat the previous search, but in the reverse direction. Spinning it back. ๐ŸŒ€
  • ESC-n โ€” repeat the previous search, but crossing file boundaries. The effect is as if the previous search were modified by *.
  • ESC-N โ€” repeat the previous search, but in the reverse direction and crossing file boundaries.
  • ESC-u โ€” undo search highlighting. Turns off highlighting of strings matching the current search pattern. If highlighting is already off because of a previous ESC-u command, it turns highlighting back on instead. Any search command will also turn highlighting back on. It also unselects any OSC 8 hyperlink that is currently selected. (Highlighting can also be disabled by toggling the -G option; in that case search commands do not turn highlighting back on, so be aware.)
  • ESC-U โ€” like ESC-u but it also clears the saved search pattern. And if the status column is enabled via the -J option, this clears all search matches marked in the status column. Full reset energy. ๐Ÿงน
  • &pattern โ€” display only lines which match the pattern; lines which do not match get hidden. If pattern is empty (if you type & immediately followed by ENTER), any filtering is turned off and all lines are displayed again. While filtering is in effect, an ampersand is displayed at the beginning of the prompt as a reminder that some lines in the file may be hidden. Multiple & commands may be entered, in which case only lines which match all of the patterns will be displayed. Filter mode is lowkey the best mode. ๐ŸŽ€

Certain characters are special as in the / command:

  • ^N or ! โ€” display only lines which do NOT match the pattern.
  • ^R โ€” don't interpret regular expression metacharacters; that is, do a simple textual comparison.

  • :e [filename] โ€” examine a new file. If the filename is missing, the "current" file (see the :n and :p commands below) from the list of files in the command line is re-examined. A percent sign (%) in the filename is replaced by the shell-escaped name of the current file. A pound sign (#) is replaced by the shell-escaped name of the previously examined file. However, two consecutive percent signs are simply replaced with a single percent sign โ€” this is how you enter a filename that contains a percent sign in the name. Similarly, two consecutive pound signs are replaced with a single pound sign. 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. If the filename contains one or more spaces, the entire filename should be enclosed in double quotes (also see the -" option). Any shell metacharacters in the filename, such as * and ?, are expanded by the shell named in the SHELL environment variable. (Note that some shells may execute external programs if certain metacharacters are used, such as backticks or dollar signs.) ๐Ÿซถ
  • ^X^V or E โ€” same as :e. Warning: some systems use ^V as a special literalization character. On such systems, you may not be able to use ^V. ๐Ÿ˜ญ
  • :n โ€” examine the next file (from the list of files given in the command line). If a number N is specified, the N-th next file is examined.
  • :p โ€” examine the previous file in the command line list. If a number N is specified, the N-th previous file is examined.
  • :x โ€” examine the first file in the command line list. If a number N is specified, the N-th file in the list is examined.
  • :d โ€” remove the current file from the list of files. bye bestie ๐Ÿ‘‹
  • t โ€” go to the next tag, if there were more than one matches for the current tag. See the -t option for more details about tags.
  • T โ€” go to the previous tag, if there were more than one matches for the current tag.
  • ^O^N or ^On โ€” search forward in the file for the N-th next OSC 8 hyperlink. ๐Ÿ”—
  • ^O^P or ^Op โ€” search backward in the file for the N-th previous OSC 8 hyperlink.
  • ^O^L or ^Ol โ€” jump to the currently selected OSC 8 hyperlink.
  • = or ^G or :f โ€” prints 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, it also prints the length of the file, the number of lines in the file and the percent of the file above the last displayed line. Stats girlies rise. โœจ
  • - โ€” followed by one of the command line option letters (see โ€œOPTIONSโ€ below), this will change the setting of that option and print a message describing the new setting. If a ^P (Ctrl+P) is entered immediately after the dash, the setting of the option is changed but no message is printed. 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.
  • -- โ€” like the - command, but it takes a long option name (see โ€œOPTIONSโ€ below) rather than a single option letter. Press ENTER or RETURN after typing the option name to change it. You can enter just the beginning of an option name, then press TAB to find all option names which begin with that string. A ^P immediately after the second dash suppresses printing of a message describing the new setting, exactly as in the - command.
  • -+ โ€” 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 does not work for string-valued options.
  • --+ โ€” like the -+ command, but it takes a long option name rather than a single option letter.
  • -! โ€” 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. This does not work for numeric or string-valued options.
  • --! โ€” like the -! command, but it takes a long option name rather than a single option letter.
  • _ โ€” (Underscore.) Followed by one of the command line option letters, this will print a message describing the current setting of that option. The setting of the option is not changed. It's giving peek-not-touch. ๐Ÿ‘€
  • __ (that's a double underscore, bestie) โ€” it's literally the glow-up of the _ (underscore) command, except instead of a single option letter you get to type a whole long option name. And yes, you have to press ENTER or RETURN after typing the option name. Commit to it. ๐Ÿ’…
  • +cmd โ€” this makes less run the cmd you specify every single time it looks at a new file, no cap. Example: +G makes less start every file at the end instead of the beginning. End-first reading, main character energy.
  • V โ€” prints the version number of the less you're running. Simple. Iconic.
  • q or Q or :q or :Q or ZZ โ€” exits less. Five whole ways to say bye, we love options. ๐Ÿฆ‹

And now the following seven commands โ€” they may or may not be valid depending on your particular installation, so vibe check your setup before you get attached. ๐Ÿ™ˆ

  • v โ€” invokes an editor to edit the current file you're viewing. The editor is taken from the environment variable VISUAL if it's defined, or EDITOR if VISUAL isn't defined, or it defaults to "vi" if neither VISUAL nor EDITOR is defined. Also go read the discussion of LESSEDIT down in the PROMPTS section below. ๐Ÿ‘€
  • ! shell-command โ€” invokes a shell to run the shell-command you gave it. Details, bestie, because there are many:
    • A percent sign (%) in the command is replaced by the name of the current file.
    • Two consecutive percent signs (%%) get replaced with a single percent sign.
    • A pound sign (#) is replaced by the name of the previously examined file.
    • Two consecutive pound signs (##) get replaced with a single pound sign.
    • "!!" repeats the last shell command.
    • "!" with no shell command invokes an interactive shell.
    • If a ^P (CONTROL-P) is entered immediately after the !, no "done" message is printed after the shell command is executed.
    • On Unix systems, the shell is taken from the environment variable SHELL, or defaults to "sh".
    • On MS-DOS, Windows, and OS/2 systems, the shell is the normal command processor.
  • # shell-command โ€” similar to the "!" command, except the command is expanded in the same way as prompt strings. For example, the name of the current file would be given as "%f". โœจ
  • | <m> shell-command โ€” <m> represents any mark character. This pipes a section of the input file to the given shell command. Now pay attention, because the boundaries are specific:
    • If the marked line is before the top line of the current screen, the section to be piped is between the marked line and the bottom line of the current screen, inclusive.
    • Otherwise (if the marked line is the top line of the current screen or after it), the section of the file to be piped is between the top line of the current screen and the marked line, inclusive.
    • <m> may also be "^" or "$" to indicate beginning or end of file respectively.
    • If <m> is "." or newline, the currently displayed screen is piped.
    • You can type ^N in place of <m> in order to enter a line number instead of a mark letter.
    • If a ^P (CONTROL-P) is entered at the start of the shell command, no "done" message is printed after the shell command is executed.
  • || <m1> <m2> shell-command โ€” like "|", it pipes a section of the input file to the given shell command, but this time the section is between the two lines marked with <m1> and <m2>, inclusive. The line marked by <m1> may be either before or after the line marked by <m2> in the file โ€” no judgment, order is fake. Either mark may be "^" or "$" to indicate beginning or end of file respectively. ":" or newline indicates the first line displayed on the screen, and ";" indicates the last line displayed on the screen. You can type ^N in place of either <m1> or <m2> in order to enter a line number instead of a mark letter.
  • s filename โ€” saves the input to a file. Heads up tho: this works only if the input is a pipe, not an ordinary file. Read that again. ๐Ÿ˜ญ
  • ^O^O โ€” runs a shell command to open the URI in the current OSC 8 hyperlink, which you selected with a previous ^O^N or ^O^P command. Here's the whole tea:
    • The shell command is given by the environment variable named "LESS_OSC8_OPEN_xxx" where "xxx" is the scheme from the URI (the part before the first colon), converted to lowercase.
    • If there is no colon in the URI, the environment variable LESS_OSC8_OPEN_NONE is used.
    • The URI from the hyperlink is then shell-escaped and appended to the value of the environment variable after a space, and the resulting string is executed as a shell command.
    • For example, if you wish to open https links by invoking a program called "mybrowser" with a "--new-window" option, you could set
LESS_OSC8_OPEN_https="mybrowser --new-window"
  • If the handler command begins with "-", the command is not displayed before it is executed.
  • If the handler command begins with ^P (CONTROL-P), the "link done" message is not displayed after it is executed.
  • If the handler command begins with ^P followed by "-", neither the command nor the "link done" message is displayed.
  • If you attempt to open a link with the "xxx" scheme and the LESS_OSC8_OPEN_xxx variable is not set, the variable LESS_OSC8_OPEN_ANY is tried. If neither LESS_OSC8_OPEN_xxx nor LESS_OSC8_OPEN_ANY is set, links using the "xxx" scheme cannot be opened.
  • However, there is a default value for LESS_OSC8_OPEN_ANY which invokes the program less-osc8-open(1). This program will open links with the schemes "man" (by running man(1)) or "file" (by running another instance of less(1) if the file is local). less-osc8-open should work on systems which provide a POSIX-compatible shell.
  • Any shell metacharacters such as semicolons, dollar signs, ampersands, etc. in the URI will be shell-escaped before the URI is appended to the handler command. If the handler passes the URI or any substring of it to a shell, it should take care to appropriately quote such strings, to prevent execution of unintended shell commands when opening a URI which contains shell metacharacters. ๐Ÿšจ
  • As a special case, if the URI begins with "#", the remainder of the URI is taken to be the value of the id parameter in another OSC 8 link in the same file, and ^O^O will simply jump to that link rather than running a handler program. Cute shortcut fr fr.
  • ^X โ€” when the "Waiting for data" message is displayed, such as while in the F command, pressing ^X will stop less from waiting and return to a prompt. Fair warning though: this may cause less to think that the file ends at the current position, so it may be necessary to use the R or F command to see more data. ๐Ÿ˜ฌ The --intr option can be used to specify a different character to use instead of ^X. This command works only on systems that support the poll(2) function. On systems without poll(2), the interrupt character (usually ^C) can be used instead.

โœจ OPTIONS โœจ

Command line options are described below, bestie. Most options may be changed while less is running, via the "-" command. Live tweaking, we love to see it. ๐Ÿ’…

Some options may be given in one of two forms: either a dash followed by a single letter, or two dashes followed by a long option name. A long option name may be abbreviated as long as the abbreviation is unambiguous. For example, --mouse may be abbreviated --mou, but not --mo, since both --mouse and --modelines begin with --mo. Don't be greedy with your abbreviations. ๐Ÿ™ˆ

Some long option names are in uppercase, such as --QUIT-AT-EOF, as distinct from --quit-at-eof. Such option names need only have their first letter capitalized; the remainder of the name may be in either case. For example, --Quit-at-eof is equivalent to --QUIT-AT-EOF. Case is lowkey flexible like that.

Options are also taken from the environment variable "LESS". For example, to avoid typing "less -options ..." each time less is invoked, you might tell csh:

setenv LESS "-options"

or if you use sh:

LESS="-options"; export LESS

On MS-DOS and Windows, you don't need the quotes, but you should be careful that any percent signs in the options string are not interpreted as an environment variable expansion. ๐Ÿ‘‘

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 variable, it can be reset to its default value on the command line by beginning the command line option with "-+".

Some options like -k or -D require a string to follow the option letter. The string for that option is considered to end when a dollar sign ($) is found. For example, you can set two -D options like this:

LESS="Dnwb$Dsbw"

If the --use-backslash option appears earlier in the options, then a dollar sign or backslash may be included literally in an option string by preceding it with a backslash. If the --use-backslash option is not in effect, then backslashes are not treated specially, and there is no way to include a dollar sign in the option string. So like, plan accordingly. ๐Ÿ˜ญ

  • -? or --help โ€” displays a summary of the commands accepted by less (the same as the h command). Depending on how your shell interprets the question mark, it may be necessary to quote the question mark, thus: "-\?". Your shell is dramatic like that. ๐Ÿ’€
  • -a or --search-skip-screen โ€” by default, forward searches start at the top of the displayed screen and backwards searches start at the bottom of the displayed screen (except for repeated searches invoked by the n or N commands, which start after or before the "target" line respectively; see the -j option for more about the target line). The -a option causes forward searches to instead start at the bottom of the screen and backward searches to start at the top of the screen, thus skipping all lines displayed on the screen. Skip the screen, skip the drama. โœจ
  • -A or --SEARCH-SKIP-SCREEN โ€” causes all forward searches (not just non-repeated searches) to start just after the target line, and all backward searches to start just before the target line. Thus, forward searches will skip part of the displayed screen (from the first line up to and including the target line). Similarly backwards searches will skip the displayed screen from the last line up to and including the target line. Fun fact: this was the default behavior in less versions prior to 441. History lesson, periodt. ๐Ÿ“œ
  • -bn or --buffers=n โ€” specifies the amount of buffer space less will use for each file, in units of kilobytes (1024 bytes). By default 64 KB of buffer space is used for each file (unless the file is a pipe; see the -B option). The -b option specifies instead that n kilobytes of buffer space should be used for each file. If n is -1, buffer space is unlimited; that is, the entire file can be read into memory. Unlimited buffer = unlimited chaos, do with that what you will. ๐Ÿ”ฅ
  • -B, --auto-buffers โ€” okay bestie, so by default, when data is read from a pipe, buffers get allocated automatically as needed. Which is chill until somebody pipes you a whole MOUNTAIN of data and suddenly a large amount of memory gets allocated ๐Ÿ˜ญ. The -B option turns OFF that automatic buffer allocation for pipes, so only 64 KB (or however much space you specified with the -b option) gets used for the pipe.
โš ๏ธ Warning: using -B can give you an erroneous display, because only the most recently viewed part of the piped data gets kept in memory โ€” any earlier data is lost. ๐Ÿ’€ And the lost characters show up as question marks.
  • -c, --clear-screen โ€” makes full screen repaints get painted from the top line down. (By default, full screen repaints happen by scrolling from the bottom of the screen.) ๐ŸŒˆ
  • -C, --CLEAR-SCREEN โ€” literally the same thing as -c, it's just here for compatibility with older versions of less. ๐Ÿ’…
  • -d, --dumb โ€” suppresses the error message you'd normally get if your terminal is dumb, meaning it's missing some important capability, like clearing the screen or scrolling backward. Other than that, -d does not change how less behaves on a dumb terminal. ๐Ÿ™ˆ
  • -Dxcolor, --color=xcolor โ€” changes the color of different parts of the displayed text. ๐ŸŽจ Here x is a single character that selects which type of text you're setting the color of:
    • B โ€” Binary characters.
    • C โ€” Control characters.
    • E โ€” Errors and informational messages.
    • H โ€” Header lines and columns, set via the --header option.
    • J โ€” Target line when highlighted via --hilite-target.
    • M โ€” Mark letters in the status column.
    • N โ€” Line numbers enabled via the -N option.
    • O โ€” OSC 8 hyperlinks.
    • P โ€” Prompts.
    • R โ€” The rscroll character.
    • S โ€” Search results.
    • T โ€” The tilde lines displayed after the end of the file or before the beginning of the file.
    • W โ€” The highlight enabled via the -w option.
    • 1-5 โ€” The text in a search result which matches the first through fifth parenthesized sub-pattern. Sub-pattern coloring works only if less is built with one of the regular expression libraries posix, pcre, or pcre2.
    • d โ€” Bold text.
    • k โ€” Blinking text.
    • s โ€” Standout text.
    • u โ€” Underlined text.

The uppercase letters and digits can be used only when the --use-color option is enabled. When text color is specified by both an uppercase letter and a lowercase letter, the uppercase letter takes precedence. โœจ For example, error messages are normally displayed as standout text. So if both "s" and "E" are given a color, the "E" color applies to error messages, and the "s" color applies to other standout text. The lowercase letters refer to bold and underline text formed by overstriking with backspaces (see the -U option) and to non-content text (such as line numbers and prompts), but not to text formatted using ANSI escape sequences with the -R option (but see the note below for different behavior on Windows and MS-DOS).

A lowercase letter may be followed by a + to indicate that the normal format change and the specified color should both be used. For example, -Dug displays underlined text as green without underlining โ€” the green color has replaced the usual underline formatting. But -Du+g displays underlined text as both green and in underlined format. ๐Ÿซถ

color is either a 4-bit color string or an 8-bit color string:

A 4-bit color string is one or two characters, where the first character specifies the foreground color and the second specifies the background color, as follows:

  • b โ€” Blue
  • c โ€” Cyan
  • g โ€” Green
  • k โ€” Black
  • m โ€” Magenta
  • r โ€” Red
  • w โ€” White
  • y โ€” Yellow

The corresponding uppercase letter denotes a brighter shade of that color. For example, -DNGk displays line numbers as bright green text on a black background, and -DEbR displays error messages as blue text on a bright red background. If either character is a "-" or is omitted, the corresponding color is set to that of normal text.

An 8-bit color string is one or two decimal integers separated by a dot, where the first integer specifies the foreground color and the second specifies the background color. Each integer is a value between 0 and 255 inclusive, which selects a "CSI 38;5" color value (an SGR escape sequence). If either integer is a "-" or is omitted, the corresponding color is set to that of normal text.

A 4-bit or 8-bit color string may be followed by one or more of the following characters to set text attributes in addition to the color. ๐Ÿ’–

  • s or ~ โ€” Standout (reverse video)
  • u or _ โ€” Underline
  • d or * โ€” Bold
  • l or & โ€” Blinking

On MS-DOS and Windows, the --color option behaves differently from what's described above, in these ways:

  • The bold (d and *) and blinking (l and &) text attributes at the end of a color string are not supported.
  • Lowercase color selector letters refer to text formatted by ANSI escape sequences with -R, in addition to overstruck and non-content text (but see -Da).
  • For historical reasons, when a lowercase color selector letter is followed by a numeric color value, the number is not interpreted as an "CSI 38;5" color value as described above, but instead as a 4-bit CHAR_INFO.Attributes value, between 0 and 15 inclusive. To avoid confusion, it is recommended that the equivalent letters rather than numbers be used after a lowercase color selector on MS-DOS/Windows.
  • Numeric color values ("CSI 38;5" color) following an uppercase color selector letter are not supported on systems earlier than Windows 10.
  • Only a limited set of ANSI escape sequences to set color in the content work correctly. 4-bit color sequences work, but "CSI 38;5" color sequences do not.
  • The -Da option makes the behavior of --color more similar to its behavior on non-MS-DOS/Windows systems by (1) making lowercase color selector letters not affect text formatted with ANSI escape sequences, and (2) allowing "CSI 38;5" color sequences in the content work by passing them to the terminal (only on Windows 10 and later; on earlier Windows systems, such sequences do not work regardless of the setting of -Da).
  • -e, --quit-at-eof โ€” makes less automatically exit the second time it reaches end-of-file. (By default, the only way out of less is the "q" command. ๐Ÿ‘‘)
  • -E, --QUIT-AT-EOF โ€” makes less automatically exit the first time it reaches end-of-file.
  • -f, --force โ€” forces non-regular files to be opened. (A non-regular file is a directory or a device special file.) It also suppresses the warning message you'd get when a binary file is opened. By default, less will refuse to open non-regular files. ๐Ÿ“ Note that some operating systems will not allow directories to be read, even if -f is set.
  • -F, --quit-if-one-screen โ€” makes less automatically exit if the entire file can be displayed on the first screen. Also peep the description of the LESS_SHELL_LINES environment variable below. ๐Ÿฆ‹
  • -g, --hilite-search โ€” normally, less highlights ALL the strings that match the last search command. The -g option changes that so it only highlights the particular string which was found by the last search command. This can make less run somewhat faster than the default. ๐Ÿ”ฅ
  • -G, --HILITE-SEARCH โ€” suppresses all highlighting of strings found by search commands. (No glow-up for your matches, sorry. ๐Ÿ’€)
  • --old-bot โ€” reverts to the old bottom of screen behavior. This can sometimes be desirable if the long lines are not wrapped correctly when reaching the bottom of the terminal, while scrolling forward.
  • -hn, --max-back-scroll=n โ€” specifies a maximum number of lines to scroll backward. If you need to scroll backward more than n lines, the screen gets repainted in a forward direction instead. (If the terminal doesn't have the ability to scroll backward, -h0 is implied.) โญ
  • -i, --ignore-case โ€” makes searches ignore case, meaning uppercase and lowercase are considered identical. This option is ignored if any uppercase letters appear in the search pattern โ€” in other words, if a pattern contains uppercase letters, then that search does not ignore case. ๐Ÿ™…โ€โ™€๏ธ
  • -I, --IGNORE-CASE โ€” like -i, but searches ignore case even if the pattern contains uppercase letters. ๐Ÿ’…
  • -jn, --jump-target=n โ€” specifies a line on the screen where the "target" line is to be positioned. The target line is the line specified by any command 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 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 second to the bottom is -2, and so on. Alternately, the screen line may be specified as a fraction of the height of the screen, starting with a decimal point: .5 is in the middle of the screen, .3 is three tenths down from the first line, and so on. If the line is specified as a fraction, the actual line number is recalculated if the terminal window is resized. ๐ŸŽ€ If the --header option is used and the target line specified by -j would be obscured by the header, the target line is moved to the first line after the header.

okay so continuing the -j saga, bestie ๐Ÿ’… โ€” if any form of the -j option is used, repeated forward searches (the ones you fire off with "n" or "N") start at the line immediately after the target line. Repeated backward searches? They start right at the target line itself. Unless -a or -A comes in and changes the whole vibe. โœจ

Like, say you used "-j4" โ€” the target line is the fourth line on the screen, so forward searches begin at the fifth line on the screen. But nonrepeated searches (the ones you kick off with "/" or "?") always begin at the first or last line on the screen respectively. fr fr. ๐Ÿฆ‹

  • -J, --status-column โ€” pops a status column at the left edge of the screen ๐Ÿ‘‘. The character hanging out in that column could be one of these:
    • > โ€” the line is chopped with the -S option, and the text that got chopped off beyond the right edge of the screen contains a match for your current search ๐Ÿ”
    • < โ€” the line is horizontally shifted, and the text shifted beyond the left side of the screen contains a match for the current search
    • = โ€” the line is both chopped and shifted, and there are matches beyond both sides of the screen
    • * โ€” there are matches in the visible part of the line, but none to the right or left of it
    • a-z, A-Z โ€” the line's been marked with that corresponding letter via the m or M command ๐Ÿ’–
    • # โ€” the line's been marked by left-clicking it with the mouse when the --mouse option is in effect ๐Ÿ–ฑ๏ธ
  • -kfilename, --lesskey-file=filename โ€” tells less to open and interpret the named file as a lesskey(5) binary file. You can stack multiple -k options if you want. If the LESSKEY or LESSKEY_SYSTEM environment variable is set, or if a lesskey file is found in a standard place (peep the KEY BINDINGS section), it gets used as a lesskey file too. โš ๏ธ Noted: there's a warning under --lesskey-content below, don't skip it.
  • --lesskey-src=filename โ€” tells less to open and interpret the named file as a lesskey(5) source file. If LESSKEYIN or LESSKEYIN_SYSTEM is set, or a lesskey source file is found in a standard place (see KEY BINDINGS), it's also used as a lesskey source file. Fun history moment ๐ŸŽ€: before version 582, you had to run the lesskey program to convert a source file into a binary file for less to use. Newer versions? They read the source file directly and ignore the binary file if the source file exists. Again โ€” warning under --lesskey-content below, bestie.
  • --lesskey-content=text โ€” tells less to interpret the specified text as the contents of a lesskey(5) source file. Inside that text, lesskey lines can be separated by newlines like usual, or by semicolons. Want a literal semicolon? Represent it with a backslash followed by a semicolon (\;). ๐Ÿ’…
Warning: some environment variables โ€” like LESS, LESSSECURE, LESSCHARSET and others that get used early in startup โ€” cannot be set in a file specified by a command line option (--lesskey, --lesskey-src or --lesskey-content). So if you're using a lesskey file to set environment variables, it's safer to use the default lesskey file, or to specify the file using the LESSKEYIN or LESSKEY_CONTENT environment variables instead of a command line option. ๐Ÿ˜ญ
  • -K, --quit-on-intr โ€” makes less bail out immediately (with status 2) the moment an interrupt character (usually Ctrl+C) gets typed. Normally? An interrupt character makes less stop whatever it's doing and come back to its command prompt. chill behaviour vs. dramatic exit, your call ๐Ÿ’€
  • -L, --no-lessopen โ€” ignores the LESSOPEN environment variable (check the INPUT PREPROCESSOR section below ๐Ÿ‘€). You can set this one from inside less too, but it'll only apply to files opened afterwards โ€” not to the file that's currently open. no take-backsies.
  • -m, --long-prompt โ€” makes less prompt verbosely (like more(1)), showing the percent into the file. By default, less just prompts with a colon :. simple queen.
  • -M, --LONG-PROMPT โ€” makes less prompt even more verbosely than more(1). maximum yapping energy, and we love that โœจ
  • -n, --line-numbers โ€” suppresses line numbers. The default (using line numbers) can make less run slower sometimes, especially with a very large input file ๐ŸŒ. What line numbers actually get you: the line number shows up in the verbose prompt and in the = command, and the v command passes the current line number to the editor (also see the discussion of LESSEDIT in PROMPTS below). ๐Ÿ“–
  • -N, --LINE-NUMBERS โ€” displays a line number at the beginning of each line in the display. so satisfying, honestly. ๐ŸŽ€
  • -ofilename, --log-file=filename โ€” makes less copy its input to the named file as it's being viewed. Heads up: this only applies when the input file is a pipe, not an ordinary file. And if the file already exists, less will ask for confirmation before overwriting it. ๐Ÿซถ
  • -Ofilename, --LOG-FILE=filename โ€” the -O option is like -o, but it overwrites an existing file without asking for confirmation. no warning, just vibes (and consequences ๐Ÿ˜ญ).

If no log file has been specified, you can use the -o and -O options from within less to specify a log file. Without a file name, they'll just report the name of the log file. And the "s" command is equivalent to specifying -o from within less. ๐Ÿ’…

  • -ppattern, --pattern=pattern โ€” the -p option on the command line is equivalent to specifying +/pattern; basically it tells less to start at the first occurrence of pattern in the file. first match, main character energy ๐Ÿ‘‘
  • -Pprompt, --prompt=prompt โ€” this is your way to tailor the three prompt styles to your own preference ๐Ÿ’–. This option would normally live in the LESS environment variable rather than being typed in with each less command. Such an option has to either be the last option in the LESS variable, or be terminated by a dollar sign.
    • -Ps โ€” followed by a string, changes the default (short) prompt to that string.
    • -Pm โ€” changes the medium (-m) prompt.
    • -PM โ€” changes the long (-M) prompt.
    • -Ph โ€” changes the prompt for the help screen.
    • -P= โ€” changes the message printed by the = command.
    • -Pw โ€” changes the message printed while waiting for data (in the "F" command).

All prompt strings are made up of a sequence of letters and special escape sequences. See the PROMPTS section for more details. โœจ

  • -q, --quiet, --silent โ€” gives you moderately "quiet" operation: the terminal bell isn't rung if you try to scroll past the end of the file or before the beginning of it. If your terminal has a "visual bell", that gets used instead. The bell will still ring on certain other errors though โ€” like typing an invalid character. The default is to ring the terminal bell in all such cases. ๐Ÿ””
  • -Q, --QUIET, --SILENT โ€” totally "quiet" operation: the terminal bell is never rung. If the terminal has a "visual bell", it's used in all cases where the terminal bell would've rung. silence, but make it aesthetic ๐Ÿคซ
  • -r, --raw-control-chars โ€” displays "raw" control characters. The default is to show control characters using caret notation; for example, a control-A (octal 001) is displayed as ^A (with some exceptions, described under the -U option). โš ๏ธ Warning: when -r is used, less can't keep track of the actual appearance of the screen (since that depends on how the screen responds to each type of control character). So various display problems can result โ€” like long lines getting split in the wrong place. ๐Ÿ˜ฌ
USE OF THE -r OPTION IS DANGEROUS AND IS NOT RECOMMENDED. The -r option can be set on the command line or via the - command, but to avoid unintentional use, it cannot be set in a LESS environment variable. If -r shows up in a LESS environment variable, it's treated as if it were -R. bestie please, just use -R. ๐Ÿ™
  • -R, --RAW-CONTROL-CHARS โ€” like -r, but only a limited set of escape sequences get output in "raw" form. Unlike -r, the screen appearance is maintained correctly. ๐Ÿ’… The sequences output raw are:
    1. ANSI SGR ("color") sequences
    2. OSC 8 hyperlinks
    3. Other OSC sequences, if the OSC type number is listed in the LESSANSIOSCALLOW environment variable
    4. OSC sequences starting with a non-standard introductory character (that is, something other than "]"), if that character is listed in the LESSANSIOSCCHARS environment variable followed by an asterisk

ANSI color escape sequences are sequences of the form:

ESC [ ... m

where the "..." is zero or more color specification characters. Color escape sequences are only supported when the color is changed within one line, not across lines. In other words, the beginning of each line is assumed to be normal (non-colored), regardless of any escape sequences in previous lines. ๐ŸŒˆ

You can make less think that characters other than "m" can end ANSI color escape sequences by setting the environment variable LESSANSIENDCHARS to the list of characters which can end a color escape sequence. And you can make less think that characters other than the standard ones may appear between the ESC and the m by setting the environment variable LESSANSIMIDCHARS to the list of characters which can appear. ๐Ÿงš

OSC sequences are of the form:

ESC ] N ; ... \7

where the OSC type number N is a decimal integer. The terminating sequence may be either a BEL character (\7) as above, or the two-character sequence "ESC \". โœจ

  • -s, --squeeze-blank-lines โ€” squeezes consecutive blank lines down into a single blank line. Super useful when you're viewing nroff(1) output. ๐Ÿ“
  • -S, --chop-long-lines โ€” makes lines longer than the screen width get chopped (truncated) instead of wrapped. Meaning: the part of a long line that doesn't fit in the screen width isn't displayed until you press RIGHT-ARROW. The default is to wrap long lines โ€” i.e. display the remainder on the next line. Also see the --wordwrap option ๐Ÿ‘€. And while the --header option is active, the -S option gets ignored, and lines longer than the screen width are truncated. โœ‚๏ธ
  • -ttag or --tag=tag โ€” okay bestie, the -t option, followed immediately by a TAG (like, no space, she's clingy), will open up the file that contains that tag. ๐Ÿ’… For this to actually work, tag info has to be available โ€” for example there might be a file chillin' in the current directory called tags, which was previously built by ctags(1) or some equivalent command. If the environment variable LESSGLOBALTAGS is set, it gets taken as the name of a command compatible with global(1), and that command gets executed to find the tag. (See the GNU global home page.) โœจ The -t option can also be specified from within less (using the - command) as a way of peeking at a new file. And the command :t is equivalent to specifying -t from within less. no cap.
  • -Ttagsfile or --tag-file=tagsfile โ€” tells less to use this specific tags file instead of "tags". simple as that, queen. ๐ŸŽ€
  • -u or --underline-special โ€” makes backspaces and carriage returns be treated as printable characters. like, they get sent straight to the terminal when they show up in the input. raw. unhinged. iconic. ๐Ÿ’…
  • -U or --UNDERLINE-SPECIAL โ€” makes backspaces, tabs, carriage returns and "formatting characters" (as defined by Unicode) be treated as control characters; that is, they get handled as specified by the -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 between two identical characters are treated specially: the overstruck text is printed using the terminal's hardware boldface capability. Other backspaces get 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. Unicode formatting characters, such as the Byte Order Mark, are sent to the terminal. Text which is overstruck or underlined can be searched for if neither -u nor -U is in effect. ๐Ÿ”

See also the --proc-backspace, --proc-tab, and --proc-return options.

  • -V or --version โ€” displays the version number of less. that's it, that's the whole vibe check. โญ
  • -w or --hilite-unread โ€” temporarily highlights the first "new" line after a movement of a full page. The first "new" line is the line immediately following the line previously at the bottom of the screen. Also highlights the target line after a g or p command. The highlight gets removed at the next command which causes movement. If the --status-line option is in effect, the entire line (the width of the screen) is highlighted. Otherwise, only the text in the line is highlighted, unless the -J option is in effect, in which case only the status column is highlighted. main character line energy fr. ๐Ÿ‘‘
  • -W or --HILITE-UNREAD โ€” like -w, but temporarily highlights the first new line after any movement command larger than one line. she's extra, we love her. ๐Ÿ’–
  • -xn,... or --tabs=n,... โ€” sets tab stops. If only one n is specified, tab stops are set at multiples of n. If multiple values separated by commas are specified, tab stops are set at those positions, and then continue with the same spacing as the last two. Position numbers are zero-based: the leftmost position is 0, the next is 1, etc. For example, "-x8,16" is the same as "-x8" and sets tabs at position 8, 16, 24, 32, etc. "-x10,14,20" will set tabs at position 10, 14, 20, 26, 32, etc. The default for n is 8. slay spacing. โœจ
  • -X or --no-init โ€” disables sending the termcap initialization and deinitialization strings to the terminal. This is sometimes desirable if initialization or deinitialization does something unnecessary, like clearing the screen. Note that some terminals require the initialization string for proper operation, so they may not behave completely correctly when -X is used. โš ๏ธ
  • -yn or --max-forw-scroll=n โ€” specifies a maximum number of lines to scroll forward. If it becomes 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. ๐ŸŒˆ
  • -zn or --window=n or -n โ€” changes 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. The "z" may be omitted for compatibility with some versions of more(1). If the number n is negative, it indicates n lines less than the current screen size. For example, if the screen is 24 lines, -z-4 sets the scrolling window to 20 lines. If the screen is later resized to 40 lines, the scrolling window automatically changes to 36 lines. adaptive queen. ๐Ÿ‘‘
  • -"cc or --quotes=cc โ€” changes the filename quoting character. This may be necessary if you're trying to name a file which contains both spaces and quote characters (chaotic, honestly). Followed by a single character, this changes the quote character to that character. Filenames containing a space should then be surrounded by that character rather than by double quotes. Followed by two characters, changes the open quote to the first character, and the close quote to the second character. Filenames containing a space should then be preceded by the open quote character and followed by the close quote character. Note that even after the quote characters are changed, this option remains -" (a dash followed by a double quote). sneaky. ๐ŸŽ€
  • -~ or --tilde โ€” normally, lines after end of file are displayed as a single tilde (~). This option causes lines after end of file to be displayed as blank lines. aesthetic choice bestie. ๐Ÿฆ‹
  • -# or --shift โ€” specifies the default number of positions to scroll horizontally in the RIGHTARROW and LEFTARROW commands. If the number specified is zero, it sets the default number of positions to one half of the screen width. Alternately, the number may be specified as a fraction of the width of the screen, starting with a decimal point: .5 is half of the screen width, .3 is three tenths of the screen width, and so on. If the number is specified as a fraction, the actual number of scroll positions gets recalculated if the terminal window is resized. math girlies rise up. โœจ
  • --autosave=actions โ€” normally, the history file is saved only when less exits. This option specifies other actions which will cause the history file to be saved. Each action is defined by a single character in the actions string:
    • m โ€” Setting or clearing a mark while --save-marks is in effect.
    • / โ€” Searching.
    • ! โ€” Running a shell command.
    • * โ€” Any action; same as "m/!".

Can be set to - to specify the default, that only exiting less will cause the history file to be saved. Note that, depending on your shell, if you specify this option on the command line, the "!" and "*" characters may need to be escaped or quoted. ๐Ÿ™ˆ

  • --cmd=commands โ€” the specified string is taken to be an initial command to less. This is similar to specifying "+commands", except that commands specified by --cmd are not executed if less exits immediately due to the use of the -E or -F option, while commands specified by the + option are executed even if less exits immediately. sneaky difference, noted. ๐Ÿ’…
  • --emouse=features โ€” features is a comma-separated list of mouse features to be enabled, selected from this list:
    • vscroll โ€” Scrolling the mouse wheel down or up moves forward or backward in the file. The number of lines to scroll when the wheel is moved can be set by the --wheel-lines option. The --rmouse option reverses the direction of movement.
    • vdrag โ€” Holding down the left button and dragging up or down moves forward or backward in the file.
    • hscroll โ€” Scrolling the side scroll wheel left or right moves left or right in the file. The number of columns to scroll when the wheel is moved can be set by the --wheel-lines option. The --rmouse option reverses the direction of movement.
    • hdrag โ€” Holding down the left button and dragging left or right moves left or right in the file.
    • lclick โ€” Left-clicking sets the "#" mark to the line where the mouse is clicked. If a left-click is performed with the mouse cursor on an OSC 8 hyperlink, the hyperlink is selected as if by the ^O^N command. If a left-click is performed with the mouse cursor on an OSC 8 hyperlink which is already selected, the hyperlink is opened as if by the ^O^O command.
    • rclick โ€” Right-clicking (or clicking any button other than the left one) returns to the "#" mark position.
    • scroll โ€” Same as "vscroll,hscroll".
    • drag โ€” Same as "vdrag,hdrag".
    • hmove โ€” Same as "hscroll,hdrag".
    • vmove โ€” Same as "vscroll,vdrag".
    • move โ€” Same as "vmove,hmove".
    • click โ€” Same as "lclick,rclick".
    • all โ€” Same as "move,click".

Each feature name may be abbreviated as long as the abbreviation is unambiguous. If features is set to -, all mouse features are disabled. Mouse input works only on terminals which support X11 mouse reporting, and on Windows. ๐Ÿญ

  • --end-prompt=string โ€” specifies a string which is printed immediately after the prompt is erased. As with the --prompt option, the first character of the string determines which prompt the string will be printed after ("s" for the short prompt, "m" for the medium prompt, or "M" for the long prompt). Special characters in the string are processed as described in the PROMPTS section, in the same way as prompts specified by the --prompt option. If set to a dash (-), nothing is printed after the prompt is erased. This option can be useful if the prompt string has been modified to contain an escape sequence that puts the terminal in a mode which should be cleared when the prompt is erased. ๐Ÿ’–
  • --exit-follow-on-close โ€” bestie, when you're using the F command on a pipe, less will just stop waiting for more data all on its own the moment the input side of the pipe gets closed. no drama, it just knows ๐Ÿ’…
  • --file-size โ€” if you pass this, less figures out the size of the file the instant it opens it. with it on, the = command and the long prompt will show you the number of lines in the file. normally less does NOT do this, because it can be slow as hell if the input file is non-seekable (like a pipe ๐Ÿšฐ) and is big.
  • --follow-name โ€” so like, normally if the input file gets renamed while an F command is running, less keeps showing you the contents of the original file even though its name changed. but with --follow-name, during an F command less will periodically try to reopen the file by name. if that reopen works and it's a different file from the original (meaning a brand new file got created with the same name as the original, which is now renamed), less shows you the contents of that new file. iconic behavior fr ๐Ÿฆ‹
  • --form-feed โ€” when you're scrolling forward or backward through the file, stop if you hit a line that begins with a form feed character (^L). lowkey so useful when you're viewing a file that puts form feeds between pages ๐Ÿ“„
  • --header=L,C,N โ€” sets how many header lines and columns get displayed on the screen. here's the breakdown:
    • the number of header lines is set to L. if L is 0, header lines are disabled. if L is empty or missing, the header line count stays unchanged.
    • the number of header columns is set to C. if C is 0, header columns are disabled. if C is empty or missing, the header column count stays unchanged.
    • the first header line is set to line number N in the file. if N is empty or missing, it's taken to be the number of the line currently displayed in the first line of the screen (if --header was issued from inside less), or 1 (if the --header option was given on the command line).
    • the special form --header=- disables both header lines and header columns, and it's equivalent to --header=0,0.

when L is nonzero, the first L lines at the top of the screen get replaced with the L lines of the file starting at line N, no matter what part of the file you're viewing. heads up tho: while header lines are displayed, any file contents before the header line can't be viewed. and when C is nonzero, the first C characters displayed at the beginning of each line get replaced with the first C characters of the line โ€” even if the rest of the line is scrolled horizontally.

one more thing bestie: while --header is active, lines longer than the screen width are truncated, and the -S option is ignored. periodt.
  • --hilite-target โ€” highlights the "target" line, which is the one set by the -j option. if --status-line is in effect, the whole line (screen width and all) gets highlighted. otherwise only the text in the line is highlighted โ€” unless -J is in effect, in which case only the status column gets highlighted โœจ
  • --incsearch โ€” search commands you run after this become "incremental". meaning less advances to the next line containing your search pattern as you type in each character of the pattern. it's giving live search ๐Ÿ”
  • --intr=c โ€” use the character c instead of ^X to interrupt a read while the "Waiting for data" message is up. c has to be an ASCII character, i.e. one with a value between 1 and 127 inclusive. you can also write a caret followed by a single character to specify a control character.
  • --line-num-width=n โ€” sets the minimum width of the line number field (when the -N option is in effect) to n characters. the default is 7.
  • --match-shift=n โ€” when -S is in effect, if a search match isn't visible because it got shifted off to the left or right of the currently visible screen, the text will horizontally shift so the search match becomes visible. this option picks the column where the first character of the search match gets placed after the shift. in other words, there will be n characters visible to the left of the search match. ๐ŸŽฏ

you can also give the number as a fraction of the screen width, starting with a decimal point: .5 is half the screen width, .3 is three tenths of the screen width, and so on. if you use a fraction, the actual number of scroll positions gets recalculated whenever the terminal window is resized. slay, adaptive.

  • --modelines=n โ€” before displaying a file, less reads the first n lines to try to find a vim-compatible modeline. if n is zero, less doesn't even try to find modelines. using a modeline means the file itself can specify the tab stops that should be used when viewing it. ๐Ÿคฏ

so a modeline contains, anywhere in the line, a program name ("vi", "vim", "ex", or "less"), followed by a colon, possibly followed by the word "set", and finally followed by zero or more option settings.

  • if the word "set" is used, option settings are separated by spaces and end at the first colon.
  • if the word "set" is not used, option settings may be separated by either spaces or colons.
  • the word "set" is required if the program name is "less", but optional if any of the other three names are used.

and if any option setting is of the form "tabstop=n" or "ts=n", then tab stops are automatically set as if --tabs=n had been given. check the --tabs description for acceptable values of n.

  • --mouse โ€” enabling --mouse is the same as --emouse=vmove,click. disabling --mouse is the same as --emouse=-. ๐Ÿญ
  • --MOUSE โ€” like --mouse but with --rmouse.
  • --no-edit-warn โ€” don't print a warning message when you use the v command on a file that was opened using a LESSOPEN preprocessor (see the INPUT PREPROCESSOR section below).
  • --no-keypad โ€” disables sending the keypad initialization and deinitialization strings to the terminal. sometimes this is useful if those keypad strings make your numeric keypad act in an undesirable manner. ๐Ÿ˜ญ
  • --no-histdups โ€” this changes the behavior so that if you type in a search string or file name and the same string is already in the history list, the existing copy gets removed from the history list before the new one is added. so a given string will appear only once in the history list. normally, a string can appear multiple times. hella tidy โœจ
  • --no-number-headers โ€” header lines (defined via the --header option) don't get assigned line numbers. line number 1 goes to the first line after any header lines. ๐Ÿ”ข
  • --no-paste โ€” if your terminal supports xterm-compatible "bracketed paste", any text pasted into less is ignored, except that one line of text may be pasted into the command line at the bottom of the screen (search strings, file names, etc). that is, the first newline of text pasted into the command line and any text after it gets ignored. ๐Ÿšซ๐Ÿ“‹
  • --no-search-header-lines โ€” searches don't include header lines, but still include header columns.
  • --no-search-header-columns โ€” searches don't include header columns, but still include header lines.
  • --no-search-headers โ€” searches don't include header lines or header columns.
  • --no-vbell โ€” disables the terminal's visual bell. ๐Ÿ”•
  • --past-eof โ€” normally, scrolling commands (other than J, K, ESC-SPACE and ESC-b) stop scrolling when end-of-file is reached scrolling forward, or beginning-of-file is reached scrolling backward. this option makes all scrolling commands keep going past end-of-file or beginning-of-file. ๐Ÿ’€
  • --proc-backspace โ€” if set, backspaces get handled as if neither the -u option nor the -U option were set. that is, a backspace next to an underscore makes text display in underline mode, and a backspace between identical characters makes text display in boldface mode. this option overrides -u and -U, so backspace display can be controlled separately from tabs and carriage returns. if not set, backspace display is controlled by -u and -U.
  • --PROC-BACKSPACE โ€” if set, backspaces get handled as if the -U option were set; that is, backspaces are treated as control characters.
  • --proc-return โ€” if set, carriage returns get handled as if neither the -u option nor the -U option were set. that is, a carriage return immediately before a newline gets deleted. this option overrides -u and -U, so carriage return display can be controlled separately from backspaces and tabs. if not set, carriage return display is controlled by -u and -U.
  • --PROC-RETURN โ€” if set, carriage returns get handled as if the -U option were set; that is, carriage returns are treated as control characters.
  • --proc-tab โ€” if set, tabs get handled as if the -U option were not set. that is, tabs are expanded to spaces. this option overrides -U, so tab display can be controlled separately from backspaces and carriage returns. if not set, tab display is controlled by -U.
  • --PROC-TAB โ€” if set, tabs get handled as if the -U option were set; that is, tabs are treated as control characters.
  • --redraw-on-quit โ€” when you quit, after sending the terminal deinitialization string, redraws the entire last screen. on terminals whose terminal deinitialization string makes the terminal switch away from an alternate screen, this makes the last screenful of the current file stay visible after less has quit. ๐ŸŽ€
  • --rmouse โ€” reverses the normal direction of scrolling when mouse scrolling is enabled via --emouse=vscroll or --emouse=hscroll. ๐Ÿ–ฑ๏ธ
  • --rscroll=c โ€” this changes the character used to mark truncated lines. it may begin with a two-character attribute indicator, same as LESSBINFMT does. if there's no attribute indicator, standout is used. if it's set to "-", truncated lines are not marked at all.
  • --save-marks โ€” bestie, this one saves your marks in the history file so they survive between separate runs of less. no more losing your spot when you quit ๐Ÿ˜ญ marks are forever now ๐Ÿ’–
  • --search-options=... โ€” sets your default search modifiers, like a lil preset vibe for every search. the value is a string of one or more of these characters: E, F, K, N, R or W. setting any of them = the exact same thing as typing that control character at the start of every search pattern. so --search-options=W is literally ^W at the beginning of every pattern, periodt. the value can also hold a digit between 1 and 5, which does the same thing as typing ^S followed by that digit at the start of every search pattern. and if the value is -, it turns off all the default search modifiers. so iconic โœจ
  • --show-preproc-errors โ€” if a LESSOPEN preprocessor makes data and then bails out with a non-zero exit code, less will show you a warning. like, not silently ghosting you, actually telling you ๐Ÿ™ˆ
  • --status-col-width=n โ€” sets how wide the status column is when the -J option is in effect. default is 2 characters. a lil slim column, slay.
  • --status-line โ€” if a line gets marked, then the entire line is highlighted instead of just the status column. also, lines highlighted because of -w or the --hilite-target option get the whole line highlighted too. and if --use-color is set, the line is colored instead of highlighted. glow up complete ๐Ÿ’…
  • --use-backslash โ€” this option changes how the options after it are interpreted. after --use-backslash, any backslash in an option string gets removed and the character right after it is taken literally. this is the moment you can sneak a dollar sign into your option strings. iykyk ๐Ÿซถ
  • --use-color โ€” enables colored text in various places. you can use the -D option to change the colors. heads up though: colored text only works if your terminal supports ANSI color escape sequences (as defined in ECMA-48). rainbow mode: activated ๐ŸŒˆ
  • --wheel-lines=n โ€” sets the number of lines or columns to scroll when you scroll the mouse wheel and the --mouse or --MOUSE option is in effect. default is 1 line or column. one lil scroll, one lil move โœจ
  • --wordwrap โ€” when the -S option is not in use, this wraps each line at a space or tab when it can, so a word doesn't get split between two lines. default behavior is to wrap at any character. your words stay whole, bestie ๐ŸŽ€
  • -- โ€” a command line argument of just -- marks the end of option arguments. anything after it gets interpreted as filenames. super useful when you're viewing a file whose name begins with a - or +. otherwise, option arguments and filename arguments can be mixed together โ€” meaning option arguments don't have to come before filename arguments, unless the environment variable POSIXLY_CORRECT is set. them's the rules ๐Ÿ’€
  • + โ€” if a command line option begins with +, the rest of that option is taken as an initial command to less. for example, +G tells less to start at the end of the file instead of the beginning, and +/xyz tells it to start at the first occurrence of "xyz" in the file. special case alert: +<number> acts like +<number>g, meaning it starts the display at the specified line number โ€” but go peep the caveat under the g command above, fr. and if the option starts with ++, that initial command applies to every file being viewed, not just the first one. the + command described earlier can also set (or change) an initial command for every file. also see the --cmd option. ๐Ÿ‘‘

๐Ÿฆ‹ LINE EDITING ๐Ÿฆ‹

okay so, when you're entering a command line at the bottom of the screen โ€” like a filename for the :e command, or the pattern for a search command โ€” certain keys let you manipulate that command line. most of these commands have an alternate form in [ brackets ] that you can use if a key doesn't exist on your particular keyboard. (quick note: the forms beginning with ESC don't work on some MS-DOS and Windows systems, because ESC is the line erase character. yeah, pain.) any of these special keys can be entered literally by putting the "literal" character in front of it โ€” either ^V or ^A. and a backslash itself can also be entered literally by entering two backslashes. writing-in-the-margins energy โœ๏ธ

  • LEFTARROW [ ESC-h ] โ€” move the cursor one space to the left. โฌ…๏ธ
  • RIGHTARROW [ ESC-l ] โ€” move the cursor one space to the right. โžก๏ธ
  • ^LEFTARROW [ ESC-b or ESC-LEFTARROW ] โ€” (that is, CONTROL and LEFTARROW at the same time.) move the cursor one word to the left. ๐Ÿงš
  • ^RIGHTARROW [ ESC-w or ESC-RIGHTARROW ] โ€” (that is, CONTROL and RIGHTARROW at the same time.) move the cursor one word to the right. ๐Ÿงš
  • HOME [ ESC-0 ] โ€” move the cursor to the beginning of the line. ๐Ÿ 
  • END [ ESC-$ ] โ€” move the cursor to the end of the line. ๐Ÿ
  • BACKSPACE โ€” delete the character to the left of the cursor, or cancel the command if the command line is empty. two jobs, one key, multitasking icon ๐Ÿ’…
  • DELETE [ ESC-x ] โ€” delete the character under the cursor. โœ‚๏ธ
  • ^BACKSPACE [ ESC-BACKSPACE ] โ€” (that is, CONTROL and BACKSPACE at the same time.) delete the word to the left of the cursor. ๐Ÿ’€
  • ^DELETE [ ESC-X or ESC-DELETE ] โ€” (that is, CONTROL and DELETE at the same time.) delete the word under the cursor. ๐Ÿ’€
  • UPARROW [ ESC-k ] โ€” retrieve the previous command line. if you first enter some text and then press UPARROW, it'll retrieve the previous command that begins with that text. history but make it filtered โœจ
  • DOWNARROW [ ESC-j ] โ€” retrieve the next command line. and same deal โ€” if you enter some text first and then press DOWNARROW, it'll retrieve the next command that begins with that text. โฌ‡๏ธ
  • TAB โ€” completes the partial filename to the left of the cursor. if it matches more than one filename, the first match gets entered into the command line, and repeated TABs cycle through the other matching filenames. if the completed filename is a directory, a / gets appended to it. (on MS-DOS and Windows systems, a \ gets appended instead.) and the environment variable LESSSEPARATOR can specify a different character to append to a directory name. autocomplete but fancy ๐ŸŽ€
  • BACKTAB (SHIFT-TAB) [ ESC-TAB ] โ€” like TAB, but it cycles in the reverse direction through the matching filenames. backwards but make it fun ๐ŸŒธ
  • ^L โ€” completes the partial filename to the left of the cursor. if it matches more than one filename, all the matches get entered into the command line โ€” that is, if they fit. all at once, no cap ๐Ÿ˜ญ
  • ^U (Unix and OS/2) or ESC (MS-DOS and Windows) โ€” delete the entire command line, or cancel the command if the cursor is at the beginning of the command line. and heads up: if you changed your line-kill character in Unix to something other than ^U, that character gets used instead of ^U. know your own settings bestie ๐Ÿซถ
  • ^G โ€” delete the entire command line and return to the main prompt. nope-ing out gracefully ๐Ÿ’…

๐Ÿ‘‘ KEY BINDINGS ๐Ÿ‘‘

you may define your own less commands by making a lesskey source file. this file specifies a set of command keys and an action associated with each key. you can also change the line-editing keys (see LINE EDITING) and set environment variables used by less. peep the lesskey(5) manual page for all the details about the file format. customizable behavior? we love to see it ๐Ÿ’–

if the environment variable LESSKEYIN is set, less uses that as the name of the lesskey source file. otherwise, less looks in a standard place for the lesskey source file:

  • on Unix systems, less looks for a lesskey file called "$XDG_CONFIG_HOME/lesskey" or "$HOME/.config/lesskey" or "$HOME/.lesskey".
  • on MS-DOS and Windows systems, less looks for a lesskey file called "$HOME/_lesskey", and if it's not found there, then it looks for a lesskey file called "_lesskey" in any directory specified in the PATH environment variable.
  • on OS/2 systems, less looks for a lesskey file called "$HOME/lesskey.ini", and if it's not found, then it looks for a lesskey file called "lesskey.ini" in any directory specified in the INIT environment variable, and if it's not found there, then it looks for a lesskey file called "lesskey.ini" in any directory specified in the PATH environment variable.

a system-wide lesskey source file may also be set up to provide key bindings. if a key is defined in both a local lesskey file and in the system-wide file, the key bindings in the local file take precedence over those in the system-wide file. local stays winning ๐Ÿ’…

if the environment variable LESSKEYIN_SYSTEM is set, less uses that as the name of the system-wide lesskey file. otherwise, less looks in a standard place:

  • on Unix systems, the system-wide lesskey file is /usr/local/etc/syslesskey. (however, if less was built with a different sysconf directory than /usr/local/etc, that directory is where the sysless file is found.)
  • on MS-DOS and Windows systems, the system-wide lesskey file is c:\_syslesskey.
  • on OS/2 systems, the system-wide lesskey file is c:\syslesskey.ini.
older versions of less (before v582) used lesskey files with a binary format, produced by the lesskey program. it is no longer necessary to use the lesskey program. glow-up complete, we don't do binary anymore bestie โœจ

๐Ÿฆ‹ INPUT PREPROCESSOR ๐Ÿฆ‹

okay bestie, this is the part where less gets โœจglow-up powersโœจ before it even opens your file. you can define an "input preprocessor" for less, and here's the vibe: before less opens a file, it first gives the input preprocessor a chance to modify the way the contents of that file get displayed. an input preprocessor is literally just an executable program (or a shell script, we love an underdog ๐Ÿซถ) that writes the contents of the file to a different file โ€” called the replacement file. the contents of the replacement file are then displayed in place of the contents of the original file. but plot twist ๐Ÿ‘€ โ€” it looks to the user like the original file is what got opened. that is, less will display the original filename as the name of the current file. no cap.

your input preprocessor receives one command line argument: the original filename, exactly as entered by the user. it should create the replacement file, and when it's done, print the name of the replacement file to its standard output. if the input preprocessor does not output a replacement filename, less uses the original file, as normal. and ngl, the input preprocessor is not called when viewing standard input. ๐Ÿšซ

to set up an input preprocessor, set the LESSOPEN environment variable to a command line that will invoke your input preprocessor. this command line should include one occurrence of the string "%s", which gets replaced by the filename when the input preprocessor command is invoked. also: two consecutive percent signs get replaced with a single percent sign. periodt. ๐Ÿ’…


when less closes a file that was opened in such a way, it will call another program โ€” the input postprocessor โ€” which may perform any desired clean-up action (such as deleting the replacement file created by LESSOPEN). this program receives two command line arguments: the original filename as entered by the user, and the name of the replacement file. to set up an input postprocessor, set the LESSCLOSE environment variable to a command line that will invoke your input postprocessor. it may include two occurrences of the string "%s" โ€” the first is replaced with the original name of the file, and the second with the name of the replacement file, which was output by LESSOPEN. and yep, two consecutive percent signs get replaced with a single percent sign. ๐Ÿ˜Œ

for example, on many Unix systems, these two scripts will let you keep files in compressed format but still let less view them directly. iconic behavior, honestly:

lessopen.sh:

#! /bin/sh
case "$1" in
*.Z) TEMPFILE=$(mktemp)
     uncompress -c $1  >$TEMPFILE  2>/dev/null
     if [ -s $TEMPFILE ]; then
          echo $TEMPFILE
     else
          rm -f $TEMPFILE
     fi
     ;;
esac

lessclose.sh:

#! /bin/sh
rm $2

to use these scripts, put them both where they can be executed and set LESSOPEN="lessopen.sh %s", and LESSCLOSE="lessclose.sh %s %s". more complex LESSOPEN and LESSCLOSE scripts may be written to accept other types of compressed files, and so on. go off, customization queen ๐Ÿ‘‘


๐ŸŒˆ the input pipe (yes, it's giving main character energy) ๐ŸŒˆ

it is also possible to set up an input preprocessor to pipe the file data directly to less, rather than putting the data into a replacement file. this avoids the need to decompress the entire file before starting to view it โ€” lowkey a huge W for speed. an input preprocessor that works this way is called an input pipe. an input pipe, instead of writing the name of a replacement file on its standard output, writes the entire contents of the replacement file on its standard output. if the input pipe does not write any characters on its standard output, then there is no replacement file and less uses the original file, as normal.

to use an input pipe, make the first character in the LESSOPEN environment variable a vertical bar (|) to signify that the input preprocessor is an input pipe. as with non-pipe input preprocessors, the command string must contain one occurrence of %s, which is replaced with the filename of the input file. ๐Ÿ’ซ

for example, on many Unix systems, this script will work like the previous example scripts:

lesspipe.sh:

#! /bin/sh
case "$1" in
*.Z) uncompress -c $1  2>/dev/null
     ;;
*)   exit 1
     ;;
esac
exit $?

to use this script, put it where it can be executed and set LESSOPEN="|lesspipe.sh %s". slay. ๐ŸŽ€

โš ๏ธ ok important caveat bestie: a preprocessor cannot output an empty file, since that is interpreted as meaning there is no replacement, and the original file is used. to avoid this, if LESSOPEN starts with two vertical bars, the exit status of the script determines the behavior when the output is empty. if the output is empty and the exit status is zero, the empty output is considered to be replacement text. if the output is empty and the exit status is nonzero, the original file is used. for compatibility with previous versions of less, if LESSOPEN starts with only one vertical bar, the exit status of the preprocessor is ignored. ๐Ÿ’€

when an input pipe is used, a LESSCLOSE postprocessor can be used, but it's usually not necessary since there's no replacement file to clean up. in this case, the replacement file name passed to the LESSCLOSE postprocessor is "-". ๐Ÿซถ

for compatibility with previous versions of less, the input preprocessor or pipe is not used if less is viewing standard input. however โ€” plot twist again โœจ โ€” if the first character of LESSOPEN is a dash (-), the input preprocessor is used on standard input as well as other files. in this case, the dash is not considered to be part of the preprocessor command. if standard input is being viewed, the input preprocessor is passed a file name consisting of a single dash. similarly, if the first two characters of LESSOPEN are vertical bar and dash (|-) or two vertical bars and a dash (||-), the input pipe is used on standard input as well as other files. again, in this case the dash is not considered to be part of the input pipe command. ๐ŸŒธ


๐Ÿ’œ default preprocessor setup ๐Ÿ’œ

there are used following files to set up default preprocessor:

/etc/profile.d/less.sh
/etc/profile.d/less.csh

these files set up /usr/bin/lesspipe.sh as a default filter. a user defined filter can be specified in ~/.lessfilter. this file should have an execute bit set and accept only one parameter, which represents a filename. if the user defined filter processes the file, zero should be returned. otherwise ~/.lessfilter tries to handle the file. and that's the whole tea โ˜•โœจ

๐ŸŒธ NATIONAL CHARACTER SETS ๐ŸŒธ

okay bestie, so here's the tea โ˜• โ€” every single character chillin' in your input file belongs to exactly one of five categories, and which category it lands in is literally what decides whether it shows up on your screen, how it shows up, or if it even gets to exist at all. the five types are:

  • normal characters โ€” these can be displayed directly to the screen, no filter needed ๐Ÿ’…
  • control characters โ€” should not be displayed directly, but you are expected to find them hanging around in ordinary text files (like backspace and tab, the classics) ๐Ÿ™ˆ
  • binary characters โ€” should not be displayed directly, and unlike control chars they're not expected to be found in text files at all ๐Ÿ’€
  • composing characters โ€” these don't get displayed separately, they just modify the display of the character that came right before them. (Only when LESSCHARSET is "utf8".) โœจ
  • deleted characters โ€” simply deleted from the input, never displayed, gone, bye. (Only when LESSCHARSET is "utf8".) ๐Ÿ—‘๏ธ

so a "character set" is just a description of which of these categories each character belongs to. that's it. that's the whole vibe check. and you pick which one less uses with the LESSCHARSET environment variable ๐ŸŒˆ

the possible values for LESSCHARSET are, and yes i'm giving you every single one, i don't gatekeep:

  • ascii โ€” BS, TAB, NL, CR, and formfeed are control characters, all chars with values between 32 and 126 are normal, and all others are binary.
  • iso8859 โ€” selects an ISO 8859 character set. this is the same as ASCII, except characters between 160 and 255 are treated as normal characters.
  • latin1 โ€” same as iso8859.
  • latin9 โ€” same as iso8859.
  • dos โ€” selects a character set appropriate for MS-DOS.
  • ebcdic โ€” selects an EBCDIC character set.
  • IBM-1047 โ€” selects an EBCDIC character set used by OS/390 Unix Services. this is the EBCDIC analogue of latin1. you get similar results by setting either LESSCHARSET=IBM-1047 or LC_CTYPE=en_US in your environment.
  • koi8-r โ€” selects a Russian character set.
  • next โ€” selects a character set appropriate for NeXT computers.
  • utf-8 โ€” selects the UTF-8 encoding of the ISO 10646 character set. UTF-8 is special bestie, it supports multi-byte characters in the input file. it is the only character set that supports multi-byte characters. main character energy honestly ๐Ÿ‘‘
  • windows โ€” selects a character set appropriate for Microsoft Windows (cp 1252).

in rare cases (and i mean rare, like, this is the deep lore) it may be desired to tailor less to use a character set other than the ones definable by LESSCHARSET. in that case, the environment variable LESSCHARDEF is your girl. set it to a string where each character in the string represents one character in the character set. the character "." is used for a normal character, "c" for control, and "b" for binary. a decimal number may be used for repetition. for example, "bccc4b." would mean character 0 is binary, 1, 2 and 3 are control, 4, 5, 6 and 7 are binary, and 8 is normal. all characters after the last are taken to be the same as the last, so characters 9 through 255 would be normal. (this is an example, and does not necessarily represent any real character set โ€” don't @ me.)

and here's the receipts, the value of LESSCHARDEF that's equivalent to each of the possible values for LESSCHARSET ๐Ÿซถ

  • ascii โ€” 8bcccbcc18b95.b
  • dos โ€” 8bcccbcc12bc5b95.b.
  • ebcdic โ€” 5bc6bcc7bcc41b.9b7.9b5.b..8b6.10b6.b9.7b9.8b8.17b3.3b9.7b9.8b8.6b10.b.b.b.
  • IBM-1047 โ€” 4cbcbc3b9cbccbccbb4c6bcc5b3cbbc4bc4bccbc191.b
  • iso8859 โ€” 8bcccbcc18b95.33b.
  • koi8-r โ€” 8bcccbcc18b95.b128.
  • latin1 โ€” 8bcccbcc18b95.33b.
  • next โ€” 8bcccbcc18b95.bb125.bb

so what happens if you set neither LESSCHARSET nor LESSCHARDEF? less has a whole decision tree and honestly it ate:

  1. if any of the strings "UTF-8", "UTF8", "utf-8" or "utf8" is found in the LC_ALL, LC_CTYPE or LANG environment variables, then the default character set is utf-8. slay.
  2. if that string is not found, but your system supports the setlocale(3) interface, less will use setlocale to determine the character set. setlocale is controlled by setting the LANG or LC_CTYPE environment variables.
  3. finally, if the setlocale interface is also not available, the default character set is utf-8. it comes home to utf-8 every time ๐Ÿ’–

now, the display part. control and binary characters are displayed in standout (reverse video). each such character is displayed in caret notation if possible (e.g. ^A for control-A). caret notation is used only if inverting the 0100 bit results in a normal printable character. otherwise, the character is displayed as a hex number in angle brackets.

that format can be changed by setting the LESSBINFMT environment variable. LESSBINFMT may begin with a "*" and one character to select the display attribute: "*k" is blinking, "*d" is bold, "*u" is underlined, "*s" is standout, and "*n" is normal. if LESSBINFMT does not begin with a "*", normal attribute is assumed. the remainder of LESSBINFMT is a string which may include one printf-style escape sequence (a % followed by x, X, o, d, etc.). for example, if LESSBINFMT is "*u[%x]", binary characters are displayed in underlined hexadecimal surrounded by brackets. the default if no LESSBINFMT is specified is "*s<%02X>".

โš ๏ธ Warning: the result of expanding the character via LESSBINFMT must be less than 31 characters. don't go overboard, bestie, there's a limit.

when the character set is utf-8, the LESSUTFBINFMT environment variable acts similarly to LESSBINFMT but it applies to Unicode code points that were successfully decoded but are unsuitable for display (e.g., unassigned code points). its default value is "<U+%04lX>". note that LESSUTFBINFMT and LESSBINFMT share their display attribute setting ("*x") so specifying one will affect both; LESSUTFBINFMT is read after LESSBINFMT so its setting, if any, will have priority. problematic octets in a UTF-8 file (octets of a truncated sequence, octets of a complete but non-shortest form sequence, invalid octets, and stray trailing octets) are displayed individually using LESSBINFMT so as to facilitate diagnostic of how the UTF-8 file is ill-formed. it's giving forensic scientist ๐Ÿ”


when the character set is utf-8, in rare cases it may be desirable to override the Unicode definition of the type of certain characters. for example, characters in a Private Use Area are normally treated as binary characters, but if you are using a custom font with printable characters in that range, it may be desirable to tell less to treat such characters as printable. you can do this by setting the LESSUTFCHARDEF environment variable to a comma-separated list of character type definitions. โœจ

each character type definition consists of either one hexadecimal codepoint or a pair of codepoints separated by a dash, followed by a colon and a type character. each hexadecimal codepoint may optionally be preceded by a "U" or "U+". if a pair of codepoints is given, the type is set for all characters inclusively between the two values. if there are multiple comma-separated codepoint values, they must be in ascending numerical order. no chaos allowed. the type character may be one of:

  • p โ€” a normal printable character.
  • w โ€” a wide (2-space) printable character.
  • b โ€” a binary (non-printable) character.
  • c โ€” a composing (zero width) character.
  • d โ€” a deleted character (deleted from the input and not displayed).

for example, setting LESSUTFCHARDEF to

E000-F8FF:p,F0000-FFFFD:p,100000-10FFFD:p

would make all Private Use Area characters be treated as printable. iconic behavior honestly ๐ŸŒŸ

by default, emoji modifiers, components and variation selectors are deleted because many terminals do not display them correctly. if you use a terminal which does display some or all of them correctly, you can cause them to be displayed by setting LESSUTFCHARDEF to treat them as composing characters. for example, this sets them all to composing characters:

FE00-FE0F:c,1F3FB-1F3FF:c,1F9B0-1F9B3:c,E0100-E01EF:c

and that's the whole charset situation, bestie ๐Ÿ’œ

๐ŸŒธ PROMPTS ๐ŸŒธ

Okay bestie, so the -P option lets you customize your prompt however you want it. The string you hand to -P replaces the specified prompt string. Certain characters inside that string get interpreted super specially. Ngl, the prompt mechanism is kinda complicated because it's built to be mad flexible โ€” but the ordinary user does not need to understand the details of constructing personalized prompt strings. So breathe. ๐Ÿซถ

A percent sign followed by a single character gets expanded based on what that following character is. (And psst โ€” any references to the input file size down below mean the preprocessed size, if an input preprocessor is being used.)

  • %bX โ€” Replaced by the byte offset into the current input file. The b is followed by a single character (shown as X above) which specifies the line whose byte offset is to be used. If the character is a "t", the byte offset of the top line in the display is used; an "m" means use the middle line; a "b" means use the bottom line; a "B" means use the line just after the bottom line; and a "j" means use the "target" line, as specified by the -j option. โœจ
  • %B โ€” Replaced by the size of the current input file. ๐Ÿ’–
  • %c โ€” Replaced by the column number of the text which appears in the first column of the screen.
  • %C โ€” Replaced by the column number of the text which appears (or would appear) in the last column of the screen.
  • %dX โ€” Replaced by the page number of a line in the input file. The line to be used is determined by the X, same as with the %b option.
  • %D โ€” Replaced by the number of pages in the input file โ€” or equivalently, the page number of the last line in the input file. ๐ŸŽ€
  • %E โ€” Replaced by the value of the VISUAL environment variable, or the EDITOR environment variable if VISUAL is not defined. See the usage example at the LESSEDIT feature below.
  • %f โ€” Replaced by the name of the current input file.
  • %F โ€” Replaced by the last component of the name of the current input file.
  • %g โ€” Replaced by the shell-escaped name of the current input file. This is useful when the expanded string will be used in a shell command, such as in LESSEDIT. ๐Ÿš
  • %G โ€” Replaced by the shell-escaped last component of the name of the current input file.
  • %i โ€” Replaced by the index of the current file in the list of input files.
  • %lX โ€” Replaced by the line number of a line in the input file. The line to be used is determined by the X, same as with the %b option.
  • %L โ€” Replaced by the line number of the last line in the input file.
  • %m โ€” Replaced by the total number of input files.
  • %pX โ€” Replaced by the percent into the current input file, based on byte offsets. The line used is determined by the X same as with the %b option.
  • %PX โ€” Replaced by the percent into the current input file, based on line numbers. The line used is determined by the X same as with the %b option.
  • %Q โ€” Replaced by the percent of the last column of text displayed on the screen compared to the length of the longest line currently displayed (that is, %C divided by %W). Heads up bestie: using this sequence can make displaying the prompt be slower than usual. ๐Ÿข
  • %s โ€” Same as %B.
  • %t โ€” Causes any trailing spaces to be removed. Usually used at the end of the string, but it may appear anywhere.
  • %T โ€” Normally expands to the word "file". However if viewing files via a tags list using the -t option, it expands to the word "tag". ๐Ÿท๏ธ
  • %W โ€” Replaced by the width of the longest line currently displayed on the screen. Note โ€” using this sequence can make displaying the prompt be slower than usual too.
  • %x โ€” Replaced by the name of the next input file in the list.
  • %y โ€” Replaced by the shell-escaped name of the next input file in the list.
  • %% โ€” Replaced by a single percent sign.

If any item is unknown (like, say, the file size if the input is a pipe), a question mark gets printed instead. ๐Ÿคท


๐Ÿฆ‹ Conditional prompts (the "IF" of it all)

The format of the prompt string can change depending on certain conditions. A question mark followed by a single character acts like an "IF": depending on the following character, a condition is evaluated. If the condition is true, any characters following the question mark and condition character โ€” up to a period โ€” are included in the prompt. If the condition is false, those characters are not included. A colon appearing between the question mark and the period sets up an "ELSE": any characters between the colon and the period are included in the string if and only if the IF condition is false. ๐Ÿ˜Œ

Condition characters (the ones that follow a question mark) may be:

  • ?a โ€” True if any characters have been included in the prompt so far.
  • ?bX โ€” True if the byte offset of the specified line is known.
  • ?B โ€” True if the size of current input file is known.
  • ?c โ€” True if the text is horizontally shifted (%c is greater than 1).
  • ?dX โ€” True if the page number of the specified line is known.
  • ?e โ€” True if at end-of-file.
  • ?f โ€” True if there is an input filename (that is, if input is not a pipe).
  • ?lX โ€” True if the line number of the specified line is known.
  • ?L โ€” True if the line number of the last line in the file is known.
  • ?m โ€” True if there is more than one input file.
  • ?n โ€” True if this is the first prompt in a new input file.
  • ?O โ€” True if an OSC 8 hyperlink is selected.
  • ?pX โ€” True if the percent into the current input file, based on byte offsets, of the specified line is known.
  • ?PX โ€” True if the percent into the current input file, based on line numbers, of the specified line is known.
  • ?Q โ€” True if %Q is less than 100. Note โ€” using this sequence can make displaying the prompt be slower than usual.
  • ?s โ€” Same as "?B".
  • ?x โ€” True if there is a next input file (that is, if the current input file is not the last one).

Any characters other than the special ones (question mark, colon, period, percent, and backslash) become literally part of the prompt. And any of the special characters can be included in the prompt literally by preceding it with a backslash. ๐Ÿ’…


๐ŸŽ€ Prompt examples, bestie

Some examples:

?f%f:Standard input.

This prompt prints the filename, if known; otherwise the string "Standard input".

?f%f .?ltLine %lt:?pt%pt\%:?btByte %bt:-...

This prompt would print the filename, if known. The filename is followed by the line number, if known, otherwise the percent if known, otherwise the byte offset if known. Otherwise, a dash is printed. Notice how each question mark has a matching period, and how the % after the %pt is included literally by escaping it with a backslash. ๐Ÿ‘‘

?n?f%f .?m(%T %i of %m) ..?e(END) ?x- Next\: %x..%t

This prints the filename if this is the first prompt in a file, followed by the "file N of N" message if there is more than one input file. Then, if we are at end-of-file, the string "(END)" is printed followed by the name of the next file, if there is one. Finally, any trailing spaces are truncated. This is the default prompt. โœจ

For reference, here are the defaults for the other two prompts โ€” -m and -M respectively. (Each is broken into two lines here for readability only.)

?n?f%f .?m(%T %i of %m) ..?e(END) ?x- Next\: %x.:
     ?pB%pB\%:byte %bB?s/%s...%t
?f%f .?n?m(%T %i of %m) ..?ltlines %lt-%lb?L/%L. :
     byte %bB?s/%s. .?e(END) ?x- Next\: %x.:?pB%pB\%..?c (column %c).%t

And here's the default message produced by the = command:

?f%f .?m(%T %i of %m) .?ltlines %lt-%lb?L/%L. .
     byte %bB?s/%s. ?e(END) :?pB%pB\%..?c (column %c).%t

๐Ÿ’œ LESSEDIT, the plot twist

The prompt expansion features are also used for another purpose: if an environment variable LESSEDIT is defined, it is used as the command to be executed when the v command is invoked. The LESSEDIT string is expanded in the same way as the prompt strings. The default value for LESSEDIT is:

%E ?lm+%lm. %g

Note that this expands to the editor name, followed by a + and the line number, followed by the shell-escaped file name. If your editor does not accept the "+linenumber" syntax, or has other differences in invocation syntax, the LESSEDIT variable can be changed to modify this default. ๐Ÿ”ง


๐Ÿ”’ SECURITY ๐Ÿ”’

Okay so when the environment variable LESSSECURE is set to 1, less runs in a "secure" mode. In this mode, these features are disabled:

  • edit โ€” the edit command (v)
  • examine โ€” the examine command (:e)
  • glob โ€” metacharacters such as * in filenames, and filename completion (TAB, ^L)
  • history โ€” history file
  • lesskey โ€” use of lesskey files, including the -k and --lesskey-src options, and all environment variables whose name begins with "LESSKEY"
  • lessopen โ€” input preprocessor (LESSOPEN environment variable)
  • logfile โ€” log files (s and -o)
  • osc8 โ€” opening OSC 8 links (^O^O)
  • pipe โ€” the pipe command (|)
  • shell โ€” the shell and pshell commands (! and #)
  • stop โ€” stopping less via a SIGTSTP signal
  • tags โ€” use of tags files (-t)

The LESSSECURE_ALLOW environment variable can be set to a comma-separated list of names of features which are selectively enabled when LESSSECURE is set. Each feature name is the first word in each line in the above list. A feature name may be abbreviated as long as the abbreviation is unambiguous. For example, if LESSSECURE=1 and LESSSECURE_ALLOW=hist,edit were set, all of the above features would be disabled except for history files and the edit command. ๐ŸŽ€

The LESSSECURE_DISALLOW environment variable can be set to a comma-separated list of names of features which are selectively disabled when LESSSECURE is not set.

less can also be compiled to be permanently in "secure" mode. In that case, all of the above features are disabled, and the LESSSECURE, LESSSECURE_ALLOW and LESSSECURE_DISALLOW variables are ignored. ๐Ÿ’€

๐Ÿ’– COMPATIBILITY WITH MORE ๐Ÿ’–

ok bestie so listen โ€” if the environment variable LESS_IS_MORE is set to 1, OR if the program gets invoked via a file link named "more" and LESS_IS_MORE is not set to 0, then less behaves (mostly) in conformance with the POSIX more(1) command spec. Basically it puts on a more costume. ๐ŸŽญ And in this mode, it does these things differently:

  • The -e option works differently. If -e is not set, less acts as if -e were set. And if -e is set, less acts as if the -E option were set instead. Yeah. It's giving chaos but ok. ๐Ÿ™ˆ
  • The -m option works differently. If -m is not set, the medium prompt is used, and it gets prefixed with the string "--More--". If -m is set, the short prompt is used.
  • The -n option acts like the -z option. So the normal behavior of -n? Not available in this mode, bestie. Gone. โœจ
  • The parameter to the -p option is taken to be a less command rather than a search pattern. Different job description entirely.
  • The LESS environment variable is ignored, and the MORE environment variable is used in its place. Swap! ๐Ÿ”„

โœจ ENVIRONMENT โœจ

ok so environment variables can be specified either in the system environment like normal, or in a lesskey(5) file. And if environment variables are defined in more than one place, here's the priority tea: variables defined in a local lesskey file take precedence over variables defined in the system environment, which take precedence over variables defined in the system-wide lesskey file. ๐Ÿ‘‘

  • COLUMNS โ€” Sets the number of columns on the screen. Takes precedence over the number of columns specified by the TERM variable. (But if you have a windowing system which supports TIOCGWINSZ or WIOCGETD, the window system's idea of the screen size takes precedence over the LINES and COLUMNS environment variables.) so basically the window wins, but only sometimes. iykyk. ๐Ÿ˜ญ
  • 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, HOMEPATH โ€” Concatenation of the HOMEDRIVE and HOMEPATH environment variables is the name of the user's home directory if the HOME variable is not set (only in the Windows version). two halves of one whole fr fr ๐Ÿซถ
  • 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_CTYPE โ€” Language for determining the character set. (yes again, both of them, that's not a typo bestie) ๐ŸŒˆ
  • LESS โ€” Options which are passed to less automatically. the autopilot settings ๐Ÿ’…
  • LESSANSIENDCHARS โ€” Characters which may end an ANSI color escape sequence (default "m").
  • LESSANSIMIDCHARS โ€” Characters which may appear between the ESC character and the end character in an ANSI color escape sequence (default "0123456789:;[?!"'#%()*+ ").
  • LESSANSIOSCALLOW โ€” A comma-separated list of OSC types which are output directly to the terminal when -R is in effect (default "8"; that is, only OSC 8 sequences are output directly).
  • LESSANSIOSCCHARS โ€” Characters which may follow an ESC character to mark the start of an "OS Command" sequence. All characters that follow this character up to a String Terminator (ESC-backslash or BEL) are considered to be part of the OSC sequence (default "]"). If a character in LESSANSIOSCCHARS is followed by an asterisk, sequences that begin with that character in the file contents are passed through to the terminal; otherwise only sequences that appear in a prompt string are passed through. ๐Ÿ“Ž
  • LESSBINFMT โ€” Format for displaying non-printable, non-control characters.
  • LESSCHARDEF โ€” Defines a character set.
  • LESSCHARSET โ€” Selects a predefined character set.
  • LESSCLOSE โ€” Command line to invoke the (optional) input-postprocessor.
  • LESSECHO โ€” Name of the lessecho program (default "lessecho"). The lessecho program is needed to expand metacharacters, such as * and ?, in filenames on Unix systems.
  • LESSEDIT โ€” Editor prototype string (used for the v command). See discussion under PROMPTS.
  • LESSGLOBALTAGS โ€” Name of the command used by the -t option to find global tags. Normally should be set to "global" if your system has the global(1) command. If not set, global tags are not used.
  • LESSHISTFILE โ€” Name 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 depends on the operating system, but is usually:
    • Linux and Unix โ€” "$XDG_STATE_HOME/lesshst" or "$HOME/.local/state/lesshst" or "$XDG_DATA_HOME/lesshst" or "$HOME/.lesshst".
    • Windows and MS-DOS โ€” "$HOME/_lesshst".
    • OS/2 โ€” "$HOME/lesshst.ini" or "$INIT/lesshst.ini".

(a whole little map of where your receipts live ๐Ÿ—บ๏ธ)

  • LESSHISTSIZE โ€” The maximum number of commands to save in the history file. The default is 100.
  • LESSKEYIN โ€” Name of the default lesskey source file.
  • LESSKEY โ€” Name of the default lesskey binary file. (Not used if "$LESSKEYIN" exists.)
  • LESSKEY_CONTENT โ€” The value is parsed as if it were the parameter of a --lesskey-content option.
  • LESSKEYIN_SYSTEM โ€” Name of the default system-wide lesskey source file.
  • LESSKEY_SYSTEM โ€” Name of the default system-wide lesskey binary file. (Not used if "$LESSKEYIN_SYSTEM" exists.)
  • LESSMETACHARS โ€” List of characters which are considered "metacharacters" by the shell.
  • LESSMETAESCAPE โ€” Prefix which less will add before each metacharacter in a command sent to the shell (default "\").
  • LESSNOCONFIG โ€” If set to "-", all environment variables except TERM are ignored (treated as if they were not set). If set to a comma-separated list of environment variable names, all environment variables except TERM and those in the list are ignored. In either case (if set to any non-empty value), all lesskey files are also ignored. straight-up silencing the whole room ๐Ÿ’€
  • LESSOPEN โ€” Command line to invoke the (optional) input-preprocessor.
  • LESSSECURE โ€” Runs less in "secure" mode. See discussion under SECURITY.
  • LESSSECURE_ALLOW โ€” Enables individual features which are normally disabled by LESSSECURE. See discussion under SECURITY.
  • LESSSECURE_DISALLOW โ€” When LESSSECURE is not set, LESSSECURE_DISALLOW can disable individual features. See discussion under SECURITY.
  • LESSSEPARATOR โ€” String to be appended to a directory name in filename completion (default "\" on MS-DOS, Windows, and OS/2; otherwise "/").
  • LESSUTFBINFMT โ€” Format for displaying non-printable Unicode code points.
  • LESSUTFCHARDEF โ€” Overrides the type of specified Unicode characters.
  • LESS_COLUMNS โ€” Sets the number of columns on the screen. Unlike COLUMNS, takes precedence over the system's idea of the screen size, so it can be used to make less use less than the full screen width. If set to a negative number, sets the number of columns used to this much less than the actual screen width. ๐Ÿ“
  • LESS_LINES โ€” Sets the number of lines on the screen. Unlike LINES, takes precedence over the system's idea of the screen size, so it can be used to make less use less than the full screen height. If set to a negative number, sets the number of lines used to this much less than the actual screen height. When set, less repaints the entire screen on every movement command, so scrolling may be slower. (pretty but expensive, the classic tradeoff ๐Ÿ˜ญ)
  • LESS_DATA_DELAY โ€” Duration (in milliseconds) after starting to read data from the input, after which the "Waiting for data" message will be displayed. The default is 4000 (4 seconds). โณ
  • LESS_IS_MORE โ€” Emulate the more(1) command.
  • LESSMSG โ€” When set to the name of a lessmsg file, messages displayed by less are taken from that file. This can be used to translate less messages into another language. See the file lessmsg in the less distribution for more details. ๐ŸŒ
  • LESS_OSC8_OPEN_xxx โ€” Where "xxx" is a URI scheme such as "http" or "file", sets an OSC 8 handler for opening OSC 8 links containing a URI with that scheme.
  • LESS_OSC8_OPEN_ANY โ€” Sets an OSC 8 handler for opening OSC 8 links for which there is no specific LESS_OSC8_OPEN_xxx handler set for the "xxx" scheme.
  • LESS_OSC8_OPEN_NONE โ€” Sets an OSC 8 handler for opening OSC 8 links which contain no scheme (that is, there is no colon in the URI). ๐Ÿซถ
  • LESS_SHELL_COPTION โ€” Normally when executing a shell command cmd (via !, #, or |, or a LESSOPEN command), if the SHELL environment variable is set, the command is invoked as "$SHELL -c cmd". If the LESS_SHELL_COPTION environment variable is set, its value is used instead of "-c" in that invocation. If LESS_SHELL_COPTION is set to a single dash, less acts as if SHELL were not set, and therefore invokes cmd directly.
  • LESS_SHELL_LINES โ€” When the -F option is set, less exits automatically if the number of screen lines used to display the file is less than or equal to the screen height minus the value of the LESS_SHELL_LINES variable. Thus, if you use a shell prompt which occupies more than one screen line, this variable can be set to the number of lines used by your prompt, to ensure that the entire file can be seen when -F is used. If not set, LESS_SHELL_LINES is assumed to be 1.
  • LESS_SIGUSR1 โ€” If set to a string of one or more less command characters, those commands will be executed when less receives a SIGUSR1 signal. โšก
  • LESS_TERMCAP_xx โ€” Where "xx" is any two characters, overrides the definition of the termcap "xx" capability for the terminal. No escape sequences in the string are processed, so any nonprintable characters such as ESC must be in the string literally.
  • LESS_TERMINFO_xxxx โ€” Where "xxxx" is any string of characters, overrides the definition of the terminfo "xxxx" capability for the terminal. You can use either LESS_TERMCAP_xx or LESS_TERMINFO_xxxx to override a terminal capability, regardless of whether less is built with the termcap or the terminfo library. ๐ŸŽ€
  • LESS_TERMCAP_BRACKETED_PASTE_START โ€” Overrides the standard ANSI escape sequence to enable bracketed paste. This is used when the --no-paste option is in effect.
  • LESS_TERMCAP_BRACKETED_PASTE_END โ€” swaps out the standard ANSI escape sequence that turns bracketed paste off. like, you're the one choosing the little "ok paste time is over" incantation ๐Ÿ’…
  • LESS_TERMCAP_MOUSE_START โ€” swaps out the standard ANSI escape sequence that turns mouse reporting on. only does anything when --mouse is in effect, bestie, so don't come for me if nothing happens ๐Ÿญ
  • LESS_TERMCAP_MOUSE_END โ€” swaps out the standard ANSI escape sequence that turns mouse reporting off.
  • LESS_TERMCAP_SUSPEND โ€” defines an escape sequence to temporarily pause screen updates. it gets yeeted to the terminal before the screen is cleared. why? to dodge screen tearing on certain terminals when the screen gets redrawn โœจ (iconic anti-tearing behaviour fr fr)
  • LESS_TERMCAP_RESUME โ€” defines an escape sequence to resume screen updates. this one gets sent to the terminal after the prompt is displayed.
  • LESS_UNSUPPORT โ€” a space-separated list of command line options. those options just get ignored, silently, no error message, no drama ๐Ÿ˜Œ โ€” whether they show up on the command line or inside the LESS environment variable. the plot twist: options listed here can still be changed by the - and -- commands. each entry is either a dash followed by a single character option letter, or two dashes followed by a long option name.
  • LINES โ€” sets how many lines fit on the screen. it takes precedence over the number of lines specified by the TERM variable. (but โ€” if you've got a windowing system that supports TIOCGWINSZ or WIOCGETD, then the window system's idea of the screen size wins over both the LINES and COLUMNS environment variables. windowing system stays undefeated ๐Ÿ‘‘)
  • MORE โ€” options that get passed to less automatically when it's running in more-compatible mode.
  • PATH โ€” the user's search path (used to find a lesskey file on MS-DOS, Windows, and OS/2 systems).
  • POSIXLY_CORRECT โ€” if it's set to any value at all, then every option argument on the command line has to come before any filename arguments. and listen โ€” this one must be set as an actual environment variable, not tucked inside a lesskey file. no shortcuts, sorry babe.
  • SHELL โ€” the shell used to run the ! command, and also to expand filenames.
  • TERM โ€” the type of terminal that less is being run on.
  • VISUAL โ€” the name of the editor, used for the v command.
  • XDG_CONFIG_HOME โ€” possible location of the lesskey file; peep the KEY BINDINGS section for the deets.
  • XDG_DATA_HOME โ€” possible location of the history file; check the description of the LESSHISTFILE environment variable.
  • XDG_STATE_HOME โ€” also a possible location of the history file; again, go read what LESSHISTFILE has to say.

๐ŸŒˆ SEE ALSO


Copyright (C) 1984-2026 Mark Nudelman

less is part of the GNU project and is free software. you can redistribute it and/or modify it under the terms of either (1) the GNU General Public License as published by the Free Software Foundation; or (2) the Less License. see the file README in the less distribution for more details about redistribution. you should have received a copy of the GNU General Public License along with the source for less; see the file COPYING. if not, write to the Free Software Foundation, 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. you should also have received a copy of the Less License; see the file LICENSE.

less is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. see the GNU General Public License for more details. (translation: it's giving free software, so pls don't sue us ๐Ÿ˜ญ)


๐Ÿ‘‘ AUTHOR

Mark Nudelman

report bugs at https://github.com/gwsw/less/issues. for more info, see the less home page.


and that's a wrap on the whole page bestie ๐ŸŽ€ you made it to the end, which is genuinely main character energy. this edition is less 710, dated 08 Sep 2026 โ€” so if you're reading this from the future, hi, hope the terminal is treating you well ๐Ÿฆ‹๐Ÿ’– now go q out of here like the icon you are โœจ

๐Ÿ“ฆ where this page comes from