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". ๐ซถ
horHโ Help: display a summary of these commands. If you forget all the other commands, remember this one. fr fr, this is your emergency contact. ๐SPACEor^Vorfor^Fโ Scroll forward N lines, default one window (see option-zbelow). If N is more than the screen size, only the final screenful is displayed. โ ๏ธ Warning: some systems use^Vas a special literalization character.zโ LikeSPACE, but if N is specified, it becomes the new window size. she's setting the rules now. ๐ENTERorRETURNor^Noreor^Eorjor^Jโ Scroll forward N lines, default 1. The entire N lines are displayed, even if N is more than the screen size.dor^Dโ Scroll forward N lines, default one half of the screen size. If N is specified, it becomes the new default for subsequentdanducommands.bor^BorESC-vโ Scroll backward N lines, default one window (see option-zbelow). If N is more than the screen size, only the final screenful is displayed.wโ LikeESC-v, but if N is specified, it becomes the new window size.yor^Yor^Porkor^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^Yas a special job control character.uor^Uโ Scroll backward N lines, default one half of the screen size. If N is specified, it becomes the new default for subsequentdanducommands.Jโ Likej, but continues to scroll beyond the end of the file. she does not know how to stop. ๐KorYโ Likek, but continues to scroll beyond the beginning of the file.ESC-SPACEโ LikeSPACE, but scrolls a full screenful, even if it reaches the end of the file.ESC-bโ Likeb, 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-)orRIGHTARROWโ Scroll horizontally right N characters, default half the screen width (see the-#option). If a number N is specified, it becomes the default for futureRIGHTARROWandLEFTARROWcommands. While the text is scrolled, it acts as though the-Soption (chop lines) were in effect.ESC-]orESC-RIGHTARROWโ Scroll horizontally right N characters likeRIGHTARROW, but stop scrolling when the last (rightmost) character on the displayed screen becomes visible at the right margin. polite. considerate. ๐ESC-(orLEFTARROWโ Scroll horizontally left N characters, default half the screen width (see the-#option). If a number N is specified, it becomes the default for futureRIGHTARROWandLEFTARROWcommands.ESC-}or^RIGHTARROWorSHIFT-RIGHTARROWโ Scroll horizontally right to show the end of the longest displayed line.ESC-{or^LEFTARROWorSHIFT-LEFTARROWโ Scroll horizontally left back to the first column.^ENDorSHIFT-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.^HOMEorSHIFT-HOMEโ Go to line N in the file, default 1 (beginning of file), and scroll horizontally left back to the first column.ror^Ror^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 thetail -fcommand.) To stop waiting for more data, enter the interrupt character (usually^C). On systems which supportpoll(2)you can also use^Xor the character specified by the--introption. If the input is a pipe and the--exit-follow-on-closeoption is in effect,lesswill automatically stop waiting for data when the input side of the pipe is closed. ๐ซถ the live-updating main character.ESC-fโ LikeF, but each time a line is found which matches the last search pattern, the terminal bell is rung. ๐ESC-Fโ LikeF, but as soon as a line is found which matches the last search pattern, the terminal bell is rung and forward scrolling stops.gor<orESC-<orHOMEโ Go to line N in the file, default 1 (beginning of file). (โ ๏ธ Warning: this may be slow if N is large.)Gor>orESC->orENDโ 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 asG, except if no number N is specified and the input is standard input, goes to the last line which is currently buffered.por%โ 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-Joption, the status column shows the marked line. bookmarking, but superior. ๐Mโ Acts likem, 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 themcommand, the last line on the screen if marked via theMcommand, or the line that was clicked if marked via the mouse). Marks are preserved when a new file is examined within a single invocation ofless, so the'command can be used to switch between input files. The--save-marksoption causes marks to be preserved across different invocations ofless. 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-ioption can be used to change this. The search starts at the first line displayed (but see the-aand-joptions, 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:
^Nor!โ Search for lines which do NOT match the pattern.
^Eor*โ 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. ๐ฆ^For@โ 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-aor-joptions 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 between1and5. 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^S1would 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 librariesposix,pcre, orpcre2.) And yes, you can stack multiple^Smodifiers, 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^Wmodifier is set, the^Emodifier 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:
^Nor!โ search for lines which do NOT match the pattern. Reverse the vibes. ๐^Eor*โ 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.^For@โ 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-aor-joptions. ๐^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^For^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 previousESC-ucommand, 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-Goption; in that case search commands do not turn highlighting back on, so be aware.)ESC-Uโ likeESC-ubut it also clears the saved search pattern. And if the status column is enabled via the-Joption, 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:
^Nor!โ 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:nand:pcommands 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:nand:pcommands. 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 theSHELLenvironment variable. (Note that some shells may execute external programs if certain metacharacters are used, such as backticks or dollar signs.) ๐ซถ^X^VorEโ same as:e. Warning: some systems use^Vas 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-toption for more details about tags.Tโ go to the previous tag, if there were more than one matches for the current tag.^O^Nor^Onโ search forward in the file for the N-th next OSC 8 hyperlink. ๐^O^Por^Opโ search backward in the file for the N-th previous OSC 8 hyperlink.^O^Lor^Olโ jump to the currently selected OSC 8 hyperlink.=or^Gor: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-bor-h), or a string value (such as-Por-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^Pimmediately 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 makeslessrun thecmdyou specify every single time it looks at a new file, no cap. Example:+Gmakes less start every file at the end instead of the beginning. End-first reading, main character energy.Vโ prints the version number of thelessyou're running. Simple. Iconic.qorQor:qor:QorZZโ exitsless. 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 variableVISUALif it's defined, orEDITORifVISUALisn't defined, or it defaults to"vi"if neitherVISUALnorEDITORis defined. Also go read the discussion ofLESSEDITdown in the PROMPTS section below. ๐! shell-commandโ invokes a shell to run theshell-commandyou 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.
- A percent sign (
# 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
^Nin 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^Nin 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^Nor^O^Pcommand. 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_NONEis 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
- The shell command is given by the environment variable named
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
^Pfollowed by"-", neither the command nor the "link done" message is displayed. - If you attempt to open a link with the
"xxx"scheme and theLESS_OSC8_OPEN_xxxvariable is not set, the variableLESS_OSC8_OPEN_ANYis tried. If neitherLESS_OSC8_OPEN_xxxnorLESS_OSC8_OPEN_ANYis set, links using the"xxx"scheme cannot be opened. - However, there is a default value for
LESS_OSC8_OPEN_ANYwhich invokes the programless-osc8-open(1). This program will open links with the schemes"man"(by runningman(1)) or"file"(by running another instance ofless(1)if the file is local).less-osc8-openshould 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 theidparameter in another OSC 8 link in the same file, and^O^Owill 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 theFcommand, pressing^Xwill stoplessfrom waiting and return to a prompt. Fair warning though: this may causelessto think that the file ends at the current position, so it may be necessary to use theRorFcommand to see more data. ๐ฌ The--introption can be used to specify a different character to use instead of^X. This command works only on systems that support thepoll(2)function. On systems withoutpoll(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 byless(the same as thehcommand). 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. ๐-aor--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 thenorNcommands, which start after or before the "target" line respectively; see the-joption for more about the target line). The-aoption 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. โจ-Aor--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 inlessversions prior to 441. History lesson, periodt. ๐-bnor--buffers=nโ specifies the amount of buffer spacelesswill 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-Boption). The-boption specifies instead thatnkilobytes of buffer space should be used for each file. Ifnis-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-Boption turns OFF that automatic buffer allocation for pipes, so only64 KB(or however much space you specified with the-boption) 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 ofless. ๐-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,-ddoes not change howlessbehaves on a dumb terminal. ๐-Dxcolor,--color=xcolorโ changes the color of different parts of the displayed text. ๐จ Herexis 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--headeroption.Jโ Target line when highlighted via--hilite-target.Mโ Mark letters in the status column.Nโ Line numbers enabled via the-Noption.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-woption.1-5โ The text in a search result which matches the first through fifth parenthesized sub-pattern. Sub-pattern coloring works only iflessis built with one of the regular expression librariesposix,pcre, orpcre2.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โ Bluecโ Cyangโ Greenkโ Blackmโ Magentarโ Redwโ Whiteyโ 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. ๐
sor~โ Standout (reverse video)uor_โ Underlinedor*โ Boldlor&โ Blinking
On MS-DOS and Windows, the --color option behaves differently from what's described above, in these ways:
- The bold (
dand*) and blinking (land&) 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-bitCHAR_INFO.Attributesvalue, between0and15inclusive. 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
-Daoption makes the behavior of--colormore 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โ makeslessautomatically exit the second time it reaches end-of-file. (By default, the only way out oflessis the"q"command. ๐)-E,--QUIT-AT-EOFโ makeslessautomatically 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,lesswill refuse to open non-regular files. ๐ Note that some operating systems will not allow directories to be read, even if-fis set.-F,--quit-if-one-screenโ makeslessautomatically exit if the entire file can be displayed on the first screen. Also peep the description of theLESS_SHELL_LINESenvironment variable below. ๐ฆ-g,--hilite-searchโ normally,lesshighlights ALL the strings that match the last search command. The-goption changes that so it only highlights the particular string which was found by the last search command. This can makelessrun 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,-h0is 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 is1, the next is2, 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:.5is in the middle of the screen,.3is 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--headeroption is used and the target line specified by-jwould 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-Soption, 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 ita-z,A-Zโ the line's been marked with that corresponding letter via themorMcommand ๐#โ the line's been marked by left-clicking it with the mouse when the--mouseoption is in effect ๐ฑ๏ธ
-kfilename,--lesskey-file=filenameโ tells less to open and interpret the named file as alesskey(5)binary file. You can stack multiple-koptions if you want. If theLESSKEYorLESSKEY_SYSTEMenvironment 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-contentbelow, don't skip it.--lesskey-src=filenameโ tells less to open and interpret the named file as alesskey(5)source file. IfLESSKEYINorLESSKEYIN_SYSTEMis 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 thelesskeyprogram 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-contentbelow, bestie.--lesskey-content=textโ tells less to interpret the specified text as the contents of alesskey(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 โ likeLESS,LESSSECURE,LESSCHARSETand others that get used early in startup โ cannot be set in a file specified by a command line option (--lesskey,--lesskey-srcor--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 theLESSKEYINorLESSKEY_CONTENTenvironment variables instead of a command line option. ๐ญ
-K,--quit-on-intrโ makes less bail out immediately (with status2) 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 theLESSOPENenvironment 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 (likemore(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 thanmore(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 thevcommand passes the current line number to the editor (also see the discussion ofLESSEDITin 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-Ooption 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-poption 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 theLESSenvironment variable rather than being typed in with each less command. Such an option has to either be the last option in theLESSvariable, 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 (octal001) is displayed as^A(with some exceptions, described under the-Uoption). โ ๏ธ Warning: when-ris 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-rOPTION IS DANGEROUS AND IS NOT RECOMMENDED. The-roption can be set on the command line or via the-command, but to avoid unintentional use, it cannot be set in aLESSenvironment variable. If-rshows up in aLESSenvironment 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:- ANSI SGR ("color") sequences
- OSC 8 hyperlinks
- Other OSC sequences, if the OSC type number is listed in the
LESSANSIOSCALLOWenvironment variable - OSC sequences starting with a non-standard introductory character (that is, something other than
"]"), if that character is listed in theLESSANSIOSCCHARSenvironment 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 viewingnroff(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--wordwrapoption ๐. And while the--headeroption is active, the-Soption gets ignored, and lines longer than the screen width are truncated. โ๏ธ-ttagor--tag=tagโ okay bestie, the-toption, 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 calledtags, which was previously built byctags(1)or some equivalent command. If the environment variableLESSGLOBALTAGSis set, it gets taken as the name of a command compatible withglobal(1), and that command gets executed to find the tag. (See the GNU global home page.) โจ The-toption can also be specified from within less (using the-command) as a way of peeking at a new file. And the command:tis equivalent to specifying-tfrom within less. no cap.-Ttagsfileor--tag-file=tagsfileโ tells less to use this specific tags file instead of"tags". simple as that, queen. ๐-uor--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. ๐-Uor--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-roption. ๐ฆ
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.
-Vor--versionโ displays the version number of less. that's it, that's the whole vibe check. โญ-wor--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 agorpcommand. The highlight gets removed at the next command which causes movement. If the--status-lineoption is in effect, the entire line (the width of the screen) is highlighted. Otherwise, only the text in the line is highlighted, unless the-Joption is in effect, in which case only the status column is highlighted. main character line energy fr. ๐-Wor--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 onenis specified, tab stops are set at multiples ofn. 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 fornis 8. slay spacing. โจ-Xor--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-Xis used. โ ๏ธ-ynor--max-forw-scroll=nโ specifies a maximum number of lines to scroll forward. If it becomes necessary to scroll forward more thannlines, the screen is repainted instead. The-cor-Coption may be used to repaint from the top of the screen if desired. By default, any forward movement causes scrolling. ๐-znor--window=nor-nโ changes the default scrolling window size tonlines. The default is one screenful. Thezandwcommands can also be used to change the window size. The"z"may be omitted for compatibility with some versions ofmore(1). If the numbernis negative, it indicatesnlines less than the current screen size. For example, if the screen is 24 lines,-z-4sets 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. ๐-"ccor--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:.5is half of the screen width,.3is 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 theactionsstring:mโ Setting or clearing a mark while--save-marksis 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--cmdare not executed if less exits immediately due to the use of the-Eor-Foption, while commands specified by the+option are executed even if less exits immediately. sneaky difference, noted. ๐--emouse=featuresโfeaturesis 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-linesoption. The--rmouseoption 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-linesoption. The--rmouseoption 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^Ncommand. 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^Ocommand.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--promptoption, 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--promptoption. 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 theFcommand 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 anFcommand is running, less keeps showing you the contents of the original file even though its name changed. but with--follow-name, during anFcommand 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
--headerwas issued from inside less), or1(if the--headeroption 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.
- the number of header lines is set to L. if L is
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--headeris active, lines longer than the screen width are truncated, and the-Soption is ignored. periodt.
--hilite-targetโ highlights the "target" line, which is the one set by the-joption. if--status-lineis in effect, the whole line (screen width and all) gets highlighted. otherwise only the text in the line is highlighted โ unless-Jis 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^Xto interrupt a read while the"Waiting for data"message is up. c has to be an ASCII character, i.e. one with a value between1and127inclusive. 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-Noption is in effect) to n characters. the default is7.--match-shift=nโ when-Sis 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--mouseis the same as--emouse=vmove,click. disabling--mouseis the same as--emouse=-. ๐ญ--MOUSEโ like--mousebut with--rmouse.--no-edit-warnโ don't print a warning message when you use thevcommand on a file that was opened using aLESSOPENpreprocessor (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--headeroption) don't get assigned line numbers. line number1goes 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 thanJ,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-uoption nor the-Uoption 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-uand-U, so backspace display can be controlled separately from tabs and carriage returns. if not set, backspace display is controlled by-uand-U.--PROC-BACKSPACEโ if set, backspaces get handled as if the-Uoption were set; that is, backspaces are treated as control characters.--proc-returnโ if set, carriage returns get handled as if neither the-uoption nor the-Uoption were set. that is, a carriage return immediately before a newline gets deleted. this option overrides-uand-U, so carriage return display can be controlled separately from backspaces and tabs. if not set, carriage return display is controlled by-uand-U.--PROC-RETURNโ if set, carriage returns get handled as if the-Uoption were set; that is, carriage returns are treated as control characters.--proc-tabโ if set, tabs get handled as if the-Uoption 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-Uoption 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=vscrollor--emouse=hscroll. ๐ฑ๏ธ--rscroll=cโ this changes the character used to mark truncated lines. it may begin with a two-character attribute indicator, same asLESSBINFMTdoes. 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 ofless. 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,RorW. setting any of them = the exact same thing as typing that control character at the start of every search pattern. so--search-options=Wis literally^Wat the beginning of every pattern, periodt. the value can also hold a digit between1and5, which does the same thing as typing^Sfollowed 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 aLESSOPENpreprocessor makes data and then bails out with a non-zero exit code,lesswill 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-Joption is in effect. default is2characters. 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-wor the--hilite-targetoption get the whole line highlighted too. and if--use-coloris 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-Doption 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--mouseor--MOUSEoption is in effect. default is1line or column. one lil scroll, one lil move โจ--wordwrapโ when the-Soption 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 variablePOSIXLY_CORRECTis set. them's the rules ๐+โ if a command line option begins with+, the rest of that option is taken as an initial command toless. for example,+Gtellslessto start at the end of the file instead of the beginning, and+/xyztells 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 thegcommand 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--cmdoption. ๐
๐ฆ 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 pressUPARROW, 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 pressDOWNARROW, 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 repeatedTABs 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 variableLESSSEPARATORcan specify a different character to append to a directory name. autocomplete but fancy ๐BACKTAB(SHIFT-TAB)[ ESC-TAB ]โ likeTAB, 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) orESC(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,
lesslooks for a lesskey file called"$XDG_CONFIG_HOME/lesskey"or"$HOME/.config/lesskey"or"$HOME/.lesskey". - on MS-DOS and Windows systems,
lesslooks 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 thePATHenvironment variable. - on OS/2 systems,
lesslooks 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 theINITenvironment variable, and if it's not found there, then it looks for a lesskey file called"lesskey.ini"in any directory specified in thePATHenvironment 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, iflesswas 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 ofless(before v582) used lesskey files with a binary format, produced by thelesskeyprogram. it is no longer necessary to use thelesskeyprogram. 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, ifLESSOPENstarts 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 ofless, ifLESSOPENstarts 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
LESSCHARSETis"utf8".) โจ - deleted characters โ simply deleted from the input, never displayed, gone, bye. (Only when
LESSCHARSETis"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 asiso8859.latin9โ same asiso8859.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 oflatin1. you get similar results by setting eitherLESSCHARSET=IBM-1047orLC_CTYPE=en_USin 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.bdosโ8bcccbcc12bc5b95.b.ebcdicโ5bc6bcc7bcc41b.9b7.9b5.b..8b6.10b6.b9.7b9.8b8.17b3.3b9.7b9.8b8.6b10.b.b.b.IBM-1047โ4cbcbc3b9cbccbccbb4c6bcc5b3cbbc4bc4bccbc191.biso8859โ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:
- if any of the strings
"UTF-8","UTF8","utf-8"or"utf8"is found in theLC_ALL,LC_CTYPEorLANGenvironment variables, then the default character set isutf-8. slay. - if that string is not found, but your system supports the
setlocale(3)interface, less will usesetlocaleto determine the character set.setlocaleis controlled by setting theLANGorLC_CTYPEenvironment variables. - finally, if the
setlocaleinterface is also not available, the default character set isutf-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-joption. โจ%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%boption.%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 theVISUALenvironment variable, or theEDITORenvironment variable ifVISUALis not defined. See the usage example at theLESSEDITfeature 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 inLESSEDIT. ๐%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%boption.%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%boption.%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%boption.%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,%Cdivided 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-toption, 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 (%cis greater than1).?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%Qis less than100. 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 filelesskeyโ use of lesskey files, including the-kand--lesskey-srcoptions, and all environment variables whose name begins with"LESSKEY"lessopenโ input preprocessor (LESSOPENenvironment variable)logfileโ log files (sand-o)osc8โ opening OSC 8 links (^O^O)pipeโ the pipe command (|)shellโ the shell and pshell commands (!and#)stopโ stoppinglessvia aSIGTSTPsignaltagsโ 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
-eoption works differently. If-eis not set,lessacts as if-ewere set. And if-eis set,lessacts as if the-Eoption were set instead. Yeah. It's giving chaos but ok. ๐ - The
-moption works differently. If-mis not set, the medium prompt is used, and it gets prefixed with the string"--More--". If-mis set, the short prompt is used. - The
-noption acts like the-zoption. So the normal behavior of-n? Not available in this mode, bestie. Gone. โจ - The parameter to the
-poption is taken to be a less command rather than a search pattern. Different job description entirely. - The
LESSenvironment variable is ignored, and theMOREenvironment 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 theTERMvariable. (But if you have a windowing system which supportsTIOCGWINSZorWIOCGETD, the window system's idea of the screen size takes precedence over theLINESandCOLUMNSenvironment variables.) so basically the window wins, but only sometimes. iykyk. ๐ญEDITORโ The name of the editor (used for thevcommand). โ๏ธHOMEโ Name of the user's home directory (used to find a lesskey file on Unix and OS/2 systems).HOMEDRIVE,HOMEPATHโ Concatenation of theHOMEDRIVEandHOMEPATHenvironment variables is the name of the user's home directory if theHOMEvariable 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 tolessautomatically. 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-Ris 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 inLESSANSIOSCCHARSis 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 thelessechoprogram (default"lessecho"). Thelessechoprogram is needed to expand metacharacters, such as*and?, in filenames on Unix systems.LESSEDITโ Editor prototype string (used for thevcommand). See discussion under PROMPTS.LESSGLOBALTAGSโ Name of the command used by the-toption to find global tags. Normally should be set to"global"if your system has theglobal(1)command. If not set, global tags are not used.LESSHISTFILEโ Name of the history file used to remember search commands and shell commands between invocations ofless. 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".
- Linux and Unix โ
(a whole little map of where your receipts live ๐บ๏ธ)
LESSHISTSIZEโ The maximum number of commands to save in the history file. The default is100.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-contentoption.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 whichlesswill add before each metacharacter in a command sent to the shell (default"\").LESSNOCONFIGโ If set to"-", all environment variables exceptTERMare ignored (treated as if they were not set). If set to a comma-separated list of environment variable names, all environment variables exceptTERMand 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โ Runslessin "secure" mode. See discussion under SECURITY.LESSSECURE_ALLOWโ Enables individual features which are normally disabled byLESSSECURE. See discussion under SECURITY.LESSSECURE_DISALLOWโ WhenLESSSECUREis not set,LESSSECURE_DISALLOWcan 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. UnlikeCOLUMNS, takes precedence over the system's idea of the screen size, so it can be used to makelessuse 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. UnlikeLINES, takes precedence over the system's idea of the screen size, so it can be used to makelessuse 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,lessrepaints 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 is4000(4 seconds). โณLESS_IS_MOREโ Emulate themore(1)command.LESSMSGโ When set to the name of a lessmsg file, messages displayed bylessare taken from that file. This can be used to translatelessmessages into another language. See the filelessmsgin thelessdistribution 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 specificLESS_OSC8_OPEN_xxxhandler 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 aLESSOPENcommand), if theSHELLenvironment variable is set, the command is invoked as"$SHELL -c cmd". If theLESS_SHELL_COPTIONenvironment variable is set, its value is used instead of"-c"in that invocation. IfLESS_SHELL_COPTIONis set to a single dash,lessacts as ifSHELLwere not set, and therefore invokes cmd directly.LESS_SHELL_LINESโ When the-Foption is set,lessexits 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 theLESS_SHELL_LINESvariable. 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-Fis used. If not set,LESS_SHELL_LINESis assumed to be1.LESS_SIGUSR1โ If set to a string of one or morelesscommand characters, those commands will be executed whenlessreceives aSIGUSR1signal. โก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 eitherLESS_TERMCAP_xxorLESS_TERMINFO_xxxxto override a terminal capability, regardless of whetherlessis 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-pasteoption 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--mouseis 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 theLESSenvironment 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 theTERMvariable. (but โ if you've got a windowing system that supportsTIOCGWINSZorWIOCGETD, then the window system's idea of the screen size wins over both theLINESandCOLUMNSenvironment variables. windowing system stays undefeated ๐)MOREโ options that get passed tolessautomatically 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 thatlessis being run on.VISUALโ the name of the editor, used for thevcommand.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 theLESSHISTFILEenvironment variable.XDG_STATE_HOMEโ also a possible location of the history file; again, go read whatLESSHISTFILEhas to say.
๐ SEE ALSO
๐ COPYRIGHT
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
- fedora 43: less 710-1.fc43 ยท (GPL-3.0-only OR BSD-2-Clause) AND GPL-2.0-or-later
- fedora 44: less 710-1.fc44 ยท (GPL-3.0-only OR BSD-2-Clause) AND GPL-2.0-or-later
- ๐ girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms