LESS(1)

๐Ÿ“ฆ version 668, in ubuntu questing

๐Ÿ’– LESS(1) ๐Ÿ’–

less is the manual page for the General Commands Manual ๐ŸŒธ

โœจ NAME โœจ

less - display the contents of a file in a terminal ๐Ÿ“–

๐ŸŽ€ SYNOPSIS ๐ŸŽ€

less -?
less --help
less -V
less --version
less [-[+]aABcCdeEfFgGiIJKLmMnNqQrRsSuUVwWX~]
     [-b space] [-h lines] [-j line] [-k keyfile]
     [-{oO} logfile] [-p pattern] [-P prompt] [-t tag]
     [-T tagsfile] [-x tab,...] [-y lines] [-[z] lines]
     [-# shift] [+[+]cmd] [--] [filename]...

(Psst, the OPTIONS section has the alternate option syntax with long option names, so go check that out too ๐Ÿ™ˆ)

๐Ÿฆ‹ DESCRIPTION ๐Ÿฆ‹

Okay so less is basically a cousin of more(1), but it has way more features ๐Ÿ’… It doesn't have to read the entire input file before it starts, so with big files it boots up faster than text editors like vi(1). Iconic behavior honestly โœจ

It uses termcap (or terminfo on some systems), so it can run on a whole bunch of different terminals ๐Ÿงš There's even limited support for hardcopy terminals. (On a hardcopy terminal, lines that should be printed at the top of the screen get a caret in front of them ๐Ÿ–จ๏ธ)

Commands are based on both more and vi, so if you've used either, you're already halfway there ๐Ÿ’œ Commands can be preceded by a decimal number, called N in the descriptions below. Some commands use it, and the ones that do will tell you so ๐Ÿ”ข

๐ŸŒˆ COMMANDS ๐ŸŒˆ

In the following descriptions, ^X means control-X. ESC stands for the ESCAPE key, so for example ESC-v means the two character sequence "ESCAPE", then "v" ๐Ÿ”‘

  • h or H โ€” Help! It displays a summary of these commands. If you forget everything else, remember this one ๐Ÿ†˜
  • SPACE or ^V or f or ^F โ€” Scrolls forward N lines, default one window (see option -z below). If N is more than the screen size, only the final screenful gets displayed. > Warning: some systems use ^V as a special literalization character, so it might not do what you expect ๐Ÿ™ƒ
  • z โ€” Like SPACE, but if N is specified, it becomes the new window size โœจ
  • ESC-SPACE โ€” Like SPACE, but it scrolls a full screenful, even if that takes you right to end-of-file ๐Ÿ
  • ENTER or RETURN or ^N or e or ^E or j or ^J โ€” Scrolls forward N lines, default 1. The entire N lines get displayed, even if N is more than the screen size ๐Ÿซถ
  • d or ^D โ€” Scrolls forward N lines, default one half of the screen size. If N is specified, it becomes the new default for later d and u commands ๐Ÿ“
  • b or ^B or ESC-v โ€” Scrolls backward N lines, default one window (see option -z below). If N is more than the screen size, only the final screenful gets displayed ๐Ÿ”™
  • w โ€” Like ESC-v, but if N is specified, it becomes the new window size ๐ŸชŸ
  • y or ^Y or ^P or k or ^K โ€” Scrolls backward N lines, default 1. The entire N lines get displayed, even if N is more than the screen size. > Warning: some systems use ^Y as a special job control character, so watch out ๐Ÿšจ
  • u or ^U โ€” Scrolls backward N lines, default one half of the screen size. If N is specified, it becomes the new default for later d and u commands ๐Ÿ‘
  • J โ€” Like j, but keeps scrolling past the end of the file ๐ŸŒŠ
  • K or Y โ€” Like k, but keeps scrolling past the beginning of the file ๐ŸŒ€
  • ESC-) or RIGHTARROW โ€” Scrolls horizontally right N characters, default half the screen width (see the -# option). If a number N is specified, it becomes the default for future RIGHTARROW and LEFTARROW commands. While the text is scrolled sideways, it acts like the -S option (chop lines) is on ๐Ÿ‘‰
  • ESC-( or LEFTARROW โ€” Scrolls horizontally left N characters, default half the screen width (see the -# option). If a number N is specified, it becomes the default for future RIGHTARROW and LEFTARROW commands ๐Ÿ‘ˆ
  • ESC-} or ^RIGHTARROW โ€” Scrolls horizontally right so you can see the end of the longest displayed line ๐Ÿƒโ€โ™€๏ธ
  • ESC-{ or ^LEFTARROW โ€” Scrolls horizontally left all the way back to the first column ๐Ÿ 
  • r or ^R or ^L โ€” Repaints the screen ๐ŸŽจ
  • R โ€” Repaints the screen and throws away any buffered input. Basically it reloads the current file. Super useful if the file is changing while you're looking at it ๐Ÿ”„
  • F โ€” Scrolls forward, and keeps trying to read when the end of file is reached. You'd normally use this when you're already at the end of the file. It's a way to watch the tail of a file that's growing while you view it ๐Ÿ‘€ (It acts similar to the tail -f command.) To stop waiting for more data, hit the interrupt character (usually ^C). On systems that support poll(2), you can also use ^X or the character specified by the --intr option. If the input is a pipe and the --exit-follow-on-close option is in effect, less will automatically stop waiting for data once the input side of the pipe is closed ๐Ÿ›‘
  • ESC-F โ€” Like F, but as soon as it finds a line matching the last search pattern, the terminal bell rings and forward scrolling stops ๐Ÿ””
  • g or < or ESC-< โ€” Goes to line N in the file, default 1 (beginning of file). > Warning: this may be slow if N is large ๐Ÿข
  • G or > or ESC-> โ€” Goes to line N in the file, default the end of the file. > Warning: this may be slow if N is large, or if N is not specified and standard input (rather than a file) is being read ๐ŸŒ
  • ESC-G โ€” Same as G, except if no number N is specified and the input is standard input, it goes to the last line that's currently buffered ๐Ÿ“ฆ
  • p or % โ€” Goes to a position N percent into the file. N should be between 0 and 100, and may contain a decimal point ๐Ÿ“
  • P โ€” Goes to the line containing byte offset N in the file ๐ŸŽฏ
  • { โ€” If a left curly bracket shows up in the top line on the screen, the { command goes to the matching right curly bracket. The matching right curly bracket gets positioned on the bottom line of the screen. If there's more than one left curly bracket on the top line, a number N can be used to pick the N-th bracket on that line ๐Ÿง
  • } โ€” If a right curly bracket shows up in the bottom line displayed on the screen, the } command goes to the matching left curly bracket. The matching left curly bracket gets positioned on the top line of the screen. If there's more than one right curly bracket on the bottom line, a number N can be used to pick the N-th bracket on that line ๐Ÿง
  • ( โ€” Like {, but for parentheses instead of curly brackets ๐ŸŒ™
  • ) โ€” Like }, but for parentheses instead of curly brackets ๐ŸŒ™
  • [ โ€” Like {, but for square brackets instead of curly brackets ๐ŸŸฆ
  • ] โ€” Like }, but for square brackets instead of curly brackets ๐ŸŸฆ
  • ESC-^F โ€” Followed by two characters, it acts like {, but uses those two characters as the open and close brackets, respectively. For example, ESC ^F < > could be used to go forward to the > that matches the < on the top displayed line ๐Ÿ”
  • ESC-^B โ€” Followed by two characters, it acts like }, but uses those two characters as the open and close brackets, respectively. For example, ESC ^B < > could be used to go backward to the < that matches the > on the bottom displayed line โช
  • m โ€” Followed by any lowercase or uppercase letter, marks the first displayed line with that letter. If the status column is enabled via the -J option, the status column shows the marked line ๐Ÿ–๏ธ
  • M โ€” Acts like m, except the last displayed line gets marked instead of the first ๐Ÿ–Š๏ธ
  • ' โ€” (Single quote.) Followed by any lowercase or uppercase letter, returns you to the position that was previously marked with that letter. Followed by another single quote, returns you to the position where the last "large" movement command was executed. Followed by a ^ or $, it jumps to the beginning or end of the file respectively. Marks are preserved when a new file is examined, so the ' command can be used to switch between input files ๐Ÿช„
  • ^X^X โ€” Same as single quote ๐Ÿช„
  • ESC-m โ€” Followed by any lowercase or uppercase letter, clears the mark identified by that letter ๐Ÿงน
  • /pattern โ€” Searches 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 your system supplies. By default, searching is case-sensitive (uppercase and lowercase are considered different), but the -i option can change that ๐Ÿ”Ž The search starts at the first line displayed (but see the -a and -j options, which change this).

Certain characters are special if you enter them at the beginning of the pattern. They modify the type of search rather than becoming part of the pattern ๐Ÿง™โ€โ™€๏ธ

  • ^N or ! โ€” Searches for lines that do NOT match the pattern ๐Ÿ™…โ€โ™€๏ธ
  • ^E or * โ€” Searches multiple files. That is, if the search reaches the END of the current file without finding a match, the search keeps going in the next file in the command line list ๐Ÿ“‚
  • ^F or @ โ€” Begins the search at the first line of the FIRST file in the command line list, no matter what's on the screen or what the -a or -j options are set to ๐Ÿ
  • ^K โ€” Highlights any text matching the pattern on the current screen, but doesn't move to the first match (you KEEP your current position) ๐Ÿ–Œ๏ธ
  • ^R โ€” Doesn't interpret regular expression metacharacters. It does a simple textual comparison instead ๐Ÿ”ค
  • ^S โ€” Followed by a digit N between 1 and 5. Only text with a non-empty match for the N-th parenthesized SUB-PATTERN will be considered a match for the pattern. (This is only supported if less is built with one of the regular expression libraries posix, pcre, or pcre2.) You can specify multiple ^S modifiers to match more than one sub-pattern ๐Ÿงฉ
  • ^W โ€” WRAPS around the current file. That is, if the search reaches the end of the current file without finding a match, it continues from the first line of the current file up to the line where it started ๐Ÿ” If the ^W modifier is set, the ^E modifier gets ignored.
  • ^L โ€” The next character is taken literally, so it becomes part of the pattern even if it's one of the search modifier characters above ๐Ÿ”’

โœจ COMMANDS โœจ (part 2, bestie, let's go ๐Ÿซถ)

  • ?pattern ๐Ÿ” โ€” okay so this one searches backward for the N-th line containing the pattern. It starts at the last line on screen (but the -a and -j options can change that, so keep an eye on them ๐Ÿ‘€).

Certain characters are super special here, same as the / command:

  • ^N or ! ๐Ÿ™…โ€โ™€๏ธ โ€” finds lines that do NOT match the pattern. Lowkey iconic.
  • ^E or * ๐ŸŒธ โ€” searches multiple files. If it hits the beginning of the current file with no match, it keeps going in the previous file in the command line list.
  • ^F or @ ๐Ÿงš โ€” starts the search at the last line of the last file in the command line list, no matter what's on screen or what -a or -j are set to.
  • ^K โ€” same as forward searches, nothing new here bestie ๐Ÿ’…
  • ^R โ€” also same as forward searches โœจ
  • ^S โ€” yep, same as forward searches too ๐Ÿ’–
  • ^W ๐ŸŒ€ โ€” WRAP around the current file. If it reaches the beginning without a match, it continues from the last line of the current file, all the way up to where it started.
  • ESC-/pattern โ€” same as "/*" ๐Ÿฆ‹
  • ESC-?pattern โ€” same as "?*" ๐Ÿฆ‹
  • n ๐Ÿ” โ€” repeats the previous search for the N-th line containing the last pattern. If the last search was modified by ^N, it finds the N-th line NOT containing the pattern. If it was modified by ^E, it continues into the next (or previous) file when the current one doesn't have what you want. If it was modified by ^R, the search skips regular expressions entirely. And if the last search was modified by ^F or ^K, n does absolutely nothing ๐Ÿ™ˆ
  • N โ€” repeats the previous search but in the reverse direction ๐Ÿ”™
  • ESC-n โ€” repeats the previous search and crosses file boundaries. It's basically like the last search was modified by * ๐ŸŒˆ
  • ESC-N โ€” reverse direction AND crossing file boundaries. Main character energy ๐Ÿ‘‘
  • ESC-u ๐Ÿงน โ€” undoes search highlighting. It turns off the highlighting for strings matching the current search pattern. If highlighting is already off because you used ESC-u before, this turns it back on. Any search command will also flip highlighting back on. (You can also disable highlighting by toggling the -G option, but in that case search commands will not turn it back on.)
  • ESC-U ๐Ÿ’€ โ€” like ESC-u, but it also clears the saved search pattern. If the status column is turned on with the -J option, this clears all the search matches marked in that column.
  • &pattern ๐ŸŽ€ โ€” displays only the lines that match the pattern. Everything else gets hidden. If the pattern is empty (you type & and then hit ENTER right away), filtering is turned off and every line shows up again. While filtering is on, an ampersand shows up at the start of the prompt as a little reminder that some lines are hidden, so don't get confused, babe ๐Ÿซถ You can stack multiple & commands, and then only lines matching all of the patterns will show.

Certain characters are special here too, same as the / command:

  • ^N or ! โ€” displays only lines that do NOT match the pattern.
  • ^R โ€” don't interpret regex metacharacters, just do a simple textual comparison ๐Ÿ“
  • :e [filename] ๐Ÿ“‚ โ€” examines a new file. If you leave out the filename, the "current" file (see :n and :p below) from the command line list gets re-examined. A percent sign (%) in the filename gets replaced by the name of the current file, and a pound sign (#) gets replaced by the name of the previously examined file. Two percent signs in a row become a single %, so you can name a file that has a percent sign in it. Same deal with two pound signs becoming one # ๐Ÿ™Œ The filename also gets added to the command line list so later :n and :p commands can see it. If you give several files, they all get added to the list and the first one gets examined. If the filename has one or more spaces, wrap the whole thing in double quotes (also see the -" option).
  • ^X^V or E โ€” same as :e ๐Ÿ’…
โš ๏ธ Warning, bestie: some systems use ^V as a special literalization character. On those, you might not be able to use ^V at all ๐Ÿ˜ญ
  • :n โญ๏ธ โ€” examines the next file from the list given on the command line. If you specify a number N, it examines the N-th next file instead.
  • :p โฎ๏ธ โ€” examines the previous file in the command line list. If you give a number N, it's the N-th previous file.
  • :x ๐Ÿฅ‡ โ€” examines the first file in the command line list. If you give a number N, it examines the N-th file in the list.
  • :d ๐Ÿ—‘๏ธ โ€” removes the current file from the list of files. Byeee ๐Ÿ‘‹
  • t ๐Ÿท๏ธ โ€” goes to the next tag, but only if the current tag has more than one match. Check the -t option for more deets on tags.
  • T โ€” goes to the previous tag, again only if the current tag has more than one match.
  • ^O^N or ^On ๐Ÿ”— โ€” searches forward in the file for the N-th next OSC 8 hyperlink.
  • ^O^P or ^Op โ€” searches backward in the file for the N-th previous OSC 8 hyperlink.
  • ^O^L or ^Ol โœจ โ€” jumps to the currently selected OSC 8 hyperlink.
  • = or ^G or :f ๐Ÿ“Š โ€” prints some info about the file you're viewing, including its name, plus the line number and byte offset of the bottom line on screen. If it's possible, it also prints the length of the file, the number of lines in it, and the percent of the file above the last displayed line. Stats-core behaviour ๐Ÿค“
  • - ๐ŸŽ›๏ธ โ€” followed by one of the command line option letters (see OPTIONS below), this changes that option's setting and prints a message describing the new setting. If you type a ^P (CONTROL-P) right after the dash, the option still changes but no message gets printed. If the option letter takes a numeric value (like -b or -h) or a string value (like -P or -t), you can type the new value right after the letter. If you don't enter a new value, you'll get a message describing the current setting and nothing changes.
  • -- โ€” like the - command, but it takes a long option name (see OPTIONS below) instead of a single letter. You have to press ENTER or RETURN after typing the name. A ^P right after the second dash suppresses the message, same as the - command ๐Ÿคซ
  • -+ ๐Ÿ”„ โ€” followed by one of the command line option letters, this resets the option to its default setting and prints 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, so don't even try ๐Ÿ™ƒ
  • --+ โ€” like the -+ command, but with a long option name instead of a single letter.
  • -! ๐Ÿ™ƒ โ€” followed by one of the command line option letters, this resets the option to the "opposite" of its default setting and prints a message describing the new setting. This does not work for numeric or string-valued options.
  • --! โ€” like the -! command, but with a long option name instead of a single letter.
  • _ (underscore) ๐Ÿ‘€ โ€” followed by one of the command line option letters, this prints a message describing the current setting of that option. The setting itself is not changed.
  • __ (double underscore) โ€” like the _ command, but takes a long option name. You must press ENTER or RETURN after typing the name.
  • +cmd ๐Ÿš€ โ€” causes the specified cmd to run every time a new file gets examined. For example, +G makes less show each file starting at the end instead of the beginning. Lowkey a game changer ๐Ÿ™Œ
  • V ๐Ÿท๏ธ โ€” prints the version number of the less you're running.
  • q or Q or :q or :Q or ZZ ๐Ÿ‘‹ โ€” exits less. Peace out โœŒ๏ธ

The following seven commands may or may not be valid, depending on your particular installation. So if one of these acts weird, it's probably your setup, not you ๐Ÿซถ

  • v ๐Ÿ“ โ€” invokes an editor to edit the current file being viewed. The editor comes from the environment variable VISUAL if it's defined. If VISUAL isn't defined, it uses EDITOR. If neither is defined, it defaults to "vi". See also the discussion of LESSEDIT under the section on PROMPTS below.
  • ! shell-command ๐Ÿš โ€” invokes a shell to run the shell-command you give it. A percent sign (%) in the command gets replaced by the name of the current file, and a pound sign (#) gets replaced by the name of the previously examined file. "!!" repeats the last shell command, and "!" with no shell command just invokes a shell. If you type a ^P (CONTROL-P) right after the !, no "done" message gets printed after the shell command runs. On Unix systems, the shell comes from the environment variable SHELL, or defaults to "sh". On MS-DOS, Windows, and OS/2 systems, the shell is the normal command processor ๐Ÿ’ป
  • # shell-command โ€” similar to the ! command, except the command gets expanded the same way as prompt strings. For example, the name of the current file would be written as "%f" ๐Ÿงฉ
  • | <m> shell-command ๐Ÿšฐ โ€” here <m> stands for any mark letter. It pipes a section of the input file to the given shell command. The section is everything between the position marked by that letter and the current screen. The entire current screen is always included, whether the marked position is before or after it. <m> can also be ^ or $ to mean the beginning or end of the file. If <m> is . or a newline, only the current screen gets piped. And if you type a ^P (CONTROL-P) right after the mark letter, no "done" message gets printed after the shell command runs.
  • s filename ๐Ÿ’พ โ€” saves the input to a file. This only works if the input is a pipe, not an ordinary file, so it's not gonna work on regular files, sorry bestie ๐Ÿฅบ
  • ^O^O โ€” okay so this one is a whole vibe ๐Ÿ’… It runs a shell command to open the URI in the current OSC 8 hyperlink, the one you picked with a previous ^O^N or ^O^P. To find that shell command, less reads the environment variable called LESS_OSC8_xxx, where xxx is the scheme from the URI (the part before the first colon), or it's empty if there's no colon in the URI at all. Then the variable's value gets expanded just like prompt strings (so any %o gets swapped out for the URI ๐Ÿซถ) to make an OSC 8 "handler" shell command. Whatever the handler spits out to standard output is an "opener" shell command, and that's what gets executed to actually open the URI โœจ

There are two special cases, and they're kind of iconic:

  1. If the URI begins with #, the rest of the URI is treated as the value of the id parameter in another OSC 8 link in the same file, and ^O^O will just jump you straight to that link ๐Ÿฆ‹
  2. If the opener begins with the characters :e followed by whitespace and a filename, then instead of running the opener as a shell command, that filename gets opened in the current instance of less ๐Ÿ“„

In a simple case where the opener takes the complete URI as a command line parameter, the handler can be as simple as:

echo mybrowser '%o'

In other cases the URI might need some tweaking first, so the handler may have to do some manipulation of the %o value ๐ŸŽ€

If the LESS_OSC8_xxx variable isn't set, less tries the variable LESS_OSC8_ANY instead. If neither LESS_OSC8_xxx nor LESS_OSC8_ANY is set, links using the "xxx" scheme just cannot be opened, bestie ๐Ÿ’€ BUT there are default handlers for the schemes "man" (used when LESS_OSC8_man isn't set) and "file" (used when LESS_OSC8_file isn't set). They should work on systems that provide the sed(1) command and a shell with syntax compatible with the Bourne shell sh(1). Now, if you use LESS_OSC8_ANY to override LESS_OSC8_file, you have to set LESS_OSC8_file to - to say "don't use the default value," and the same goes for LESS_OSC8_man ๐Ÿ™ˆ

The URI passed to an OSC8 handler via %o is guaranteed to NOT contain any single quote or double quote characters. It can contain other shell metacharacters like semicolons, dollar signs, ampersands, etc., so the handler needs to carefully quote its parameters in the opener command. Otherwise opening a URI full of metacharacters could run unintended shell commands ๐Ÿ˜ญ Also, since the handler command gets expanded like a command prompt, any metacharacters that prompt expansion interprets (like percent, dot, colon, backslash, etc.) must be escaped with a backslash. Check the PROMPTS section for the deets ๐ŸŒธ
  • ^X โ€” when the "Waiting for data" message is showing, like while you're in the F command, pressing ^X stops less from waiting and drops you back to a prompt โœจ Heads up though: this might make less think the file ends at the current position, so you may need to use the R or F command to see more data. The --intr option lets you pick a different character to use instead of ^X. This command only works on systems that support the poll(2) function. On systems without poll(2), the interrupt character (usually ^C) can be used instead ๐Ÿ’–

โœจ OPTIONS โœจ

Command line options are described below, and most of them can be changed while less is running, via the - command ๐Ÿงš

Some options can 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 can be abbreviated as long as the abbreviation is unambiguous. For example, --quit-at-eof can be shortened to --quit, but NOT --qui, because both --quit-at-eof and --quiet begin with --qui ๐Ÿ™…โ€โ™€๏ธ Some long option names are in uppercase, like --QUIT-AT-EOF, which is different from --quit-at-eof. Those only need their first letter capitalized, and the rest can be in either case. So --Quit-at-eof is equivalent to --QUIT-AT-EOF ๐ŸŽ€

Options are also taken from the environment variable LESS. For example, so you don't have to type less -options ... every single time, you could 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 be careful that any percent signs in the options string aren't interpreted as an environment variable expansion ๐Ÿ‘€

The environment variable gets parsed before the command line, so command line options override the LESS environment variable. If an option appears in the LESS variable, you can reset it to its default value on the command line by starting the command line option with -+ ๐Ÿ”„

Some options, like -k or -D, need a string to follow the option letter. That string 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 can be included literally in an option string by putting a backslash in front of it. If --use-backslash is NOT in effect, backslashes aren't treated specially, and there's no way to include a dollar sign in the option string ๐Ÿ˜ค

  • -?, --help โ€” shows a summary of the commands less accepts (same as the h command) ๐Ÿ“– Depending on how your shell interprets the question mark, you might need to quote it, like this: -\?.
  • -a, --search-skip-screen โ€” by default, forward searches start at the top of the displayed screen and backward searches start at the bottom (except for repeated searches from the n or N commands, which start after or before the "target" line respectively; check the -j option for more on the target line ๐ŸŽฏ). The -a option flips it so forward searches start at the bottom of the screen and backward searches start at the top, which skips all the lines already displayed on screen โœจ
  • -A, --SEARCH-SKIP-SCREEN โ€” makes ALL forward searches (not just the non-repeated ones) start just after the target line, and ALL backward searches start just before the target line. So forward searches skip part of the displayed screen (from the first line up to and including the target line), and backward searches skip the displayed screen from the last line up to and including the target line. This was the default behavior in less versions prior to 441 ๐Ÿ•ฐ๏ธ
  • -bn, --buffers=n โ€” sets how much buffer space less uses for each file, in kilobytes (1024 bytes each). By default you get 64 KB per file (unless the file is a pipe; see the -B option). The -b option lets you choose n kilobytes instead. If n is -1, the buffer space is unlimited, which means the entire file can be read into memory ๐Ÿง 
  • -B, --auto-buffers โ€” by default, when data is read from a pipe, buffers get allocated automatically as needed. If a large amount of data comes through the pipe, that can eat up a lot of memory ๐Ÿ˜ต The -B option turns off this automatic buffer allocation for pipes, so only 64 KB (or whatever amount the -b option specifies) is used.
Warning: using -B can result in erroneous display, since only the most recently viewed part of the piped data is kept in memory. Any earlier data is lost, and lost characters get displayed as question marks โ“
  • -c, --clear-screen โ€” makes full screen repaints paint from the top line down. By default, full screen repaints scroll from the bottom of the screen instead ๐ŸŒˆ
  • -C, --CLEAR-SCREEN โ€” same as -c, kept around for compatibility with older versions of less ๐Ÿ‘ต
  • -d, --dumb โ€” suppresses the error message that normally shows up if the terminal is dumb, meaning it's missing some important capability like clearing the screen or scrolling backward ๐Ÿ’€ The -d option doesn't change anything else about how less behaves on a dumb terminal.
  • -Dxcolor, --color=xcolor โ€” changes the color of different parts of the displayed text ๐ŸŒˆ x is a single character that picks which type of text gets its color set:
    • B โ€” Binary characters.
    • C โ€” Control characters.
    • E โ€” Errors and informational messages.
    • H โ€” Header lines and columns, set via the --header option.
    • M โ€” Mark letters in the status column.
    • N โ€” Line numbers enabled via the -N option.
    • P โ€” Prompts.
    • R โ€” The rscroll character.
    • S โ€” Search results.
    • W โ€” The highlight enabled via the -w option.
    • 1-5 โ€” The text in a search result that matches the first through fifth parenthesized sub-pattern. Sub-pattern coloring only works if less is built with one of the regular expression libraries posix, pcre, or pcre2 ๐Ÿ”
    • d โ€” Bold text.
    • k โ€” Blinking text.
    • s โ€” Standout text.
    • u โ€” Underlined text.

The uppercase letters and digits can only be used when the --use-color option is enabled. If a text color is specified by both an uppercase and a lowercase letter, the uppercase one takes precedence. For example, error messages are normally displayed as standout text, so if both s and E get a color, the E color applies to error messages and the s color applies to everything else that's standout ๐Ÿ’… The lowercase letters refer to bold and underline text formed by overstriking with backspaces (see the -U option) and to non-content text (like line numbers and prompts), but NOT to text formatted with ANSI escape sequences under the -R option. (Check the note below for different behavior on Windows and MS-DOS ๐Ÿซถ)

Okay so bestie, we're picking up right where the -D color stuff left off, and it gets so detailed ๐Ÿ˜ญ๐ŸŽ€

A lowercase letter can be followed by a + ๐Ÿ’… which means you get the normal format change AND the color you picked. For example, -Dug shows underlined text as green without underlining, because green took over the usual underline look. But -Du+g gives you both green and underlined โœจ Iconic.

color is either a 4-bit color string or an 8-bit color string ๐ŸŒˆ

4-bit color strings are one or two characters. The first one picks the foreground color and the second picks the background ๐ŸŽจ

  • b โ€” Blue ๐Ÿ’™
  • c โ€” Cyan ๐Ÿฉต
  • g โ€” Green ๐Ÿ’š
  • k โ€” Black ๐Ÿ–ค
  • m โ€” Magenta ๐Ÿ’œ
  • r โ€” Red โค๏ธ
  • w โ€” White ๐Ÿค
  • y โ€” Yellow ๐Ÿ’›

Uppercase version = a brighter shade โœจ So -DNGk makes line numbers bright green on black, and -DEbR makes error messages blue on a bright red background ๐Ÿ˜ญ If either character is a - or you just leave it out, that part goes back to normal text, no cap.

8-bit color strings are one or two decimal integers separated by a dot ๐Ÿงš The first is the foreground, the second is the background. Each number is between 0 and 255 inclusive, and it picks a CSI 38;5 color value (see https://en.wikipedia.org/wiki/ANSI_escape_code#SGR). Same deal here: a - or a missing number means normal text.

A 4-bit or 8-bit color string can also be followed by one or more of these attribute characters to add text styling on top of the color ๐Ÿ’–

  • s or ~ โ€” Standout (reverse video) ๐Ÿ”„
  • u or _ โ€” Underline ๐Ÿซถ
  • d or * โ€” Bold ๐Ÿ’ช
  • l or & โ€” Blinking ๐Ÿšจ
Heads up, MS-DOS and Windows peeps ๐Ÿ™ˆ The --color option acts a little different over there, in these ways:
  • The bold (d and *) and blinking (l and &) attributes at the end of a color string are not supported ๐Ÿ’€
  • Lowercase color selector letters also refer to text formatted with ANSI escape sequences using -R, plus 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 read as a CSI 38;5 color value. Instead it's a 4-bit CHAR_INFO.Attributes value, between 0 and 15 inclusive (see https://learn.microsoft.com/en-us/windows/console/char-info-str).
    • To avoid confusion, use the matching letters instead of numbers after a lowercase color selector on MS-DOS/Windows. Trust ๐Ÿซถ
  • Numeric color values (CSI 38;5 color) after an uppercase color selector letter are not supported on systems older than Windows 10 ๐Ÿ˜ญ
  • Only a limited set of ANSI escape sequences that set color in the content work properly. 4-bit color sequences work, but CSI 38;5 color sequences do not ๐Ÿ’”
  • The -Da option makes --color act more like it does on non-MS-DOS/Windows systems ๐Ÿ‘‘ It does this 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 to work by passing them through to the terminal. That second part only works on Windows 10 and later; on earlier Windows systems those sequences don't work no matter what -Da is set to ๐Ÿ˜ญ

  • -e, --quit-at-eof โ€” Makes less auto-exit the second time it hits end-of-file โœจ By default, the only way out of less is the q command ๐Ÿšช
  • -E, --QUIT-AT-EOF โ€” Makes less auto-exit the first time it hits end-of-file ๐Ÿƒโ€โ™€๏ธ
  • -f, --force โ€” Forces non-regular files to open ๐Ÿ”“ (A non-regular file is a directory or a device special file.) It also hides the warning you get when a binary file is opened ๐Ÿ™ˆ By default, less refuses to open non-regular files. Heads up: some operating systems won't let directories be read even if -f is set ๐Ÿ’€
  • -F, --quit-if-one-screen โ€” Makes less auto-exit if the whole file fits on the first screen ๐ŸŒธ
  • -g, --hilite-search โ€” Normally less highlights ALL strings matching the last search command. -g changes that so only the one particular string found by the last search gets highlighted โœจ This can make less run a bit faster than the default ๐ŸŽ๏ธ
  • -G, --HILITE-SEARCH โ€” Turns off ALL highlighting of strings found by searches ๐Ÿซฅ
  • -hn, --max-back-scroll=n โ€” Sets the max number of lines you can scroll backward ๐Ÿ”™ If you need to scroll back more than n lines, the screen gets repainted in a forward direction instead. (If your terminal can't scroll backward, -h0 is implied ๐Ÿ’…)
  • -i, --ignore-case โ€” Makes searches ignore case, so uppercase and lowercase count as the same ๐Ÿค BUT this gets ignored if any uppercase letters show up in the search pattern. In other words, if your pattern has uppercase letters, that search stays case-sensitive ๐Ÿ™ƒ
  • -I, --IGNORE-CASE โ€” Same as -i, except searches ignore case EVEN if the pattern has uppercase letters ๐Ÿซจ
  • -jn, --jump-target=n โ€” Picks the screen line where the "target" line gets placed ๐ŸŽฏ The target line is whichever line gets landed on by any command that searches for a pattern, jumps to a line number, jumps to a file percentage, or jumps to a tag. You can give the screen line as a number: the top line is 1, the next is 2, and so on. You can also use a negative number to count from the bottom: the bottom line is -1, second to bottom is -2, etc. Or you can use a fraction of the screen height, starting with a decimal point: .5 is the middle of the screen, .3 is three tenths down from the first line, and so on ๐ŸŒˆ If you use a fraction, the actual line number gets recalculated when the terminal window is resized ๐Ÿ“ If the --header option is used and the target line from -j would be hidden by the header, the target line gets moved to the first line after the header ๐Ÿ™Œ While --header is active, the -S option is ignored, and lines longer than the screen width get truncated โœ‚๏ธ

If you use ANY form of -j, repeated forward searches (started with n or N) begin at the line right after the target line, and repeated backward searches begin at the target line itself, unless you change that with -a or -A ๐Ÿ’ซ For example, if you use -j4, the target line is the fourth line on the screen, so forward searches start at the fifth line on the screen. Nonrepeated searches (started with / or ?) always start at the start or end of the current screen, respectively ๐Ÿง 

  • -J, --status-column โ€” Shows a status column on the left edge of the screen ๐Ÿ‘€ The character in that column can be one of these:
    • > โ€” The line is chopped with -S, and the text chopped off past the right edge of the screen contains a match for the current search โžก๏ธ
    • < โ€” The line is horizontally shifted, and the text shifted past the left side of the screen contains a match for the current search โฌ…๏ธ
    • = โ€” The line is both chopped and shifted, and there are matches past both sides of the screen ๐Ÿคฏ
    • * โ€” There are matches in the visible part of the line, but none to the right or left of it โญ
    • a-z, A-Z โ€” The line has been marked with that letter using the m command ๐Ÿ–๏ธ
  • -kfilename, --lesskey-file=filename โ€” Makes less open and read the named file as a lesskey(1) binary file ๐Ÿ“‚ You can use multiple -k options. If the LESSKEY or LESSKEY_SYSTEM environment variable is set, or if a lesskey file is found in a standard place (see KEY BINDINGS), that gets used as a lesskey file too ๐Ÿซถ Note the warning under "--lesskey-content" below โš ๏ธ
  • --lesskey-src=filename โ€” Makes less open and read the named file as a lesskey(1) source file ๐Ÿ“ If the LESSKEYIN or LESSKEYIN_SYSTEM environment variable is set, or if a lesskey source file is found in a standard place (see KEY BINDINGS), that gets used as a lesskey source file too ๐Ÿ’… Before version 582, you had to run the lesskey program to convert a lesskey source file into a lesskey binary file for less to use ๐Ÿฅฑ Newer versions of less read the source file directly and ignore the binary file if the source file exists. Main character behavior ๐Ÿ‘‘ Note the warning under "--lesskey-content" below โš ๏ธ
  • --lesskey-content=text โ€” Makes less interpret the text you give it as the contents of a lesskey(1) source file โœจ In that text, lesskey lines can be separated by normal newlines, or by semicolons ๐Ÿง To include a literal semicolon, put a backslash in front of it, like \;. Hmm, careful: the original says "a backslash followed by a semicolon", so write it as \ followed by ;.
Warning โš ๏ธ Certain environment variables like LESS, LESSSECURE, LESSCHARSET, and others, which are used super early during startup, can NOT be set in a file given by a command line option (--lesskey, --lesskey-src or --lesskey-content). If you want to use a lesskey file to set environment variables, it's safer to use the default lesskey file, or to point to the file with the LESSKEYIN or LESSKEY_CONTENT environment variables instead of a command line option ๐Ÿฅบ๐Ÿ’€

Oops, I left some drafting notes in that last draft. Here is the clean version of the final lesskey-content line and the rest of the part:

  • --lesskey-content=text โ€” Makes less interpret the text you give it as the contents of a lesskey(1) source file โœจ In that text, lesskey lines can be separated by normal newlines, or by semicolons ๐Ÿง To include a literal semicolon, put a backslash in front of it, so a backslash followed by a semicolon.
Warning โš ๏ธ Certain environment variables like LESS, LESSSECURE, LESSCHARSET, and others, which get used super early during startup, can NOT be set in a file specified by a command line option (--lesskey, --lesskey-src or --lesskey-content). If you want a lesskey file to set environment variables, it's safer to use the default lesskey file, or to specify the file with the LESSKEYIN or LESSKEY_CONTENT environment variables instead of a command line option ๐Ÿฅบ๐Ÿ’€
  • -K, --quit-on-intr โ€” okay so this one makes less bail straight out with exit status 2 the moment you hit an interrupt character (usually ^C) ๐Ÿ’€. Normally ^C just stops whatever less is doing and sends you back to its command prompt, but with this on, that doesn't happen. Heads up bestie, using this means you can't get back to the command prompt from the F command ๐Ÿ˜ญ.
  • -L, --no-lessopen โ€” this tells less to ignore the LESSOPEN environment variable ๐Ÿ™ˆ (see the INPUT PREPROCESSOR section below). You can flip it on from inside less too, but it only applies to files opened after that. The file currently open stays the same.
  • -m, --long-prompt โ€” makes less prompt verbosely, like more(1) does, and shows the percent into the file ๐Ÿ“–. By default less keeps it chill with a colon.
  • -M, --LONG-PROMPT โ€” prompts even more verbosely than more(1). Extra dramatic, extra detail โœจ.
  • -n, --line-numbers โ€” suppresses line numbers ๐Ÿซถ. Line numbers are on by default, but in some cases they can make less run more slowly, especially with a really huge input file. Turning them off with -n avoids that problem. When line numbers are in use, the line number shows up in the verbose prompt and in the = command, and the v command passes the current line number to the editor (see also the discussion of LESSEDIT in PROMPTS below).
  • -N, --LINE-NUMBERS โ€” puts a line number at the start of each line in the display ๐Ÿ“.
  • -ofilename, --log-file=filename โ€” makes less copy its input into the named file while you're viewing it ๐Ÿ“. This only works when the input is a pipe, not an ordinary file. If the file already exists, less will ask you to confirm before it overwrites it.
  • -Ofilename, --LOG-FILE=filename โ€” same vibe as -o, but this one overwrites an existing file without asking ๐Ÿ”ฅ.

If you haven't specified a log file yet, you can use -o and -O from inside less to pick one. If you leave out the file name, they'll just tell you the name of the log file that's already set. The s command does the same thing as -o from inside less ๐Ÿ’….

  • -ppattern, --pattern=pattern โ€” -p on the command line is the same as typing +/pattern. In other words, less starts at the first occurrence of pattern in the file ๐Ÿฆ‹.
  • -Pprompt, --prompt=prompt โ€” this is how you customise the three prompt styles to your own taste ๐ŸŽ€. You'd usually put this in the LESS environment variable instead of typing it every single time. The option has to be the last one in the LESS variable, or it has to end with 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 letters and special escape sequences. Check the PROMPTS section for the full tea โ˜•.

  • -q, --quiet or --silent โ€” moderately "quiet" mode ๐Ÿคซ. The terminal bell won't ring if you try to scroll past the end or before the beginning of the file. If the terminal has a "visual bell", that gets used instead. The bell still rings for certain other errors, like typing an invalid character. By default, the bell rings in all of these cases.
  • -Q, --QUIET or --SILENT โ€” totally silent mode ๐ŸŒ™. The terminal bell is never rung. If the terminal has a "visual bell", that's used in every case where the bell would've gone off.
  • -r, --raw-control-chars โ€” shows "raw" control characters ๐Ÿ‘€. By default, control characters use caret notation, so a control-A (octal 001) shows up as "^A" (with some exceptions, as described under the -U option).
โš ๏ธ Warning: when you use -r, less can't keep track of what the screen actually looks like, because that depends on how the screen responds to each control character. So you can get display problems, like long lines getting split in the wrong place.
๐Ÿšซ USE OF THE -r OPTION IS NOT RECOMMENDED.
  • -R, --RAW-CONTROL-CHARS โ€” like -r, but only ANSI "color" escape sequences and OSC 8 hyperlink sequences get output in "raw" form ๐ŸŒˆ. Unlike -r, the screen appearance stays correct, as long as the file doesn't contain any escape sequences besides these types. Color escape sequences only work when the color changes within one line, not across lines. So the start of each line is assumed to be normal (non-colored), no matter what escape sequences came before it. For keeping track of the screen, these escape sequences are assumed not to move the cursor.

OSC 8 hyperlinks look like this:

ESC ] 8 ; ... \7

The ending can be either a BEL character (\7) or the two-character sequence "ESC \".

ANSI color escape sequences look like this:

ESC [ ... m

where the "..." is zero or more color specification characters. If you want less to think other characters can end an ANSI color escape sequence, set the LESSANSIENDCHARS environment variable to the list of characters that can end one. And if characters other than the standard ones can show up between the ESC and the m, set the LESSANSIMIDCHARS environment variable to the list of characters that can appear there ๐Ÿงš.

  • -s, --squeeze-blank-lines โ€” squishes consecutive blank lines down into a single blank line ๐Ÿงฝ. This is handy when you're viewing nroff output.
  • -S, --chop-long-lines โ€” chops long lines (truncates them) instead of wrapping them when they're wider than the screen โœ‚๏ธ. So the part of a long line that doesn't fit isn't shown until you press RIGHT-ARROW. Wrapping is the default, meaning the rest of the line shows up on the next line. See also the --wordwrap option.
  • -ttag, --tag=tag โ€” -t followed right away by a TAG opens the file that contains that tag ๐Ÿท๏ธ. For this to work, the tag info has to exist. For example, there might be a file in the current directory called "tags" that was built earlier by ctags(1) or something equivalent. If the LESSGLOBALTAGS environment variable is set, it's treated as the name of a command compatible with global(1), and that command gets run to find the tag (see http://www.gnu.org/software/global/global.html). You can also use -t from inside less (with the - command) to look at a new file. The :t command does the same thing as -t from inside less.
  • -Ttagsfile, --tag-file=tagsfile โ€” uses the tags file you name here instead of "tags" ๐Ÿ“‚.
  • -u, --underline-special โ€” makes backspaces and carriage returns count as printable characters ๐Ÿ–Š๏ธ. So they get sent to the terminal whenever they show up in the input.
  • -U, --UNDERLINE-SPECIAL โ€” makes backspaces, tabs, carriage returns and "formatting characters" (as defined by Unicode) count as control characters ๐ŸŽญ. That means they're handled the way the -r option says.

By default, if you give neither -u nor -U, things get handled with a bit of finesse. A backspace right next to an underscore is treated specially: the underlined text shows up using the terminal's hardware underlining. A backspace between two identical characters is also special: the overstruck text gets printed using the terminal's hardware boldface. Any other backspaces get deleted, along with the character before them. A carriage return immediately followed by a newline is deleted. Other carriage returns get handled the way the -r option says. Unicode formatting characters, like the Byte Order Mark, are sent to the terminal. Overstruck or underlined text can be searched, as long as neither -u nor -U is in effect.

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

  • -V, --version โ€” shows the version number of less ๐Ÿ”ข.
  • -w, --hilite-unread โ€” briefly highlights the first "new" line after a full page of forward movement ๐Ÿ’ก. The first "new" line is the one right after the line that used to be at the bottom of the screen. It also highlights the target line after a g or p command. The highlight disappears at the next command that causes movement. If the --status-line option is in effect, the whole line (the full width of the screen) gets highlighted. Otherwise, only the text on the line is highlighted, unless the -J option is in effect, in which case only the status column is highlighted.
  • -W, --HILITE-UNREAD โ€” like -w, but it highlights the first new line after any forward movement command that's bigger than one line ๐ŸŒŸ.
  • -xn,..., --tabs=n,... โ€” sets tab stops ๐Ÿ“. If you specify only one n, tab stops land on multiples of n. If you give several values separated by commas, the tab stops go at those positions, and then continue with the same spacing as the last two. For example, -x9,17 sets tabs at positions 9, 17, 25, 33, and so on. The default for n is 8.
  • -X, --no-init โ€” stops less from sending the termcap initialization and deinitialization strings to the terminal ๐Ÿ™…. This is sometimes what you want if the deinitialization string does something unnecessary, like clearing the screen.
  • -yn, --max-forw-scroll=n โ€” okay so this one caps how far forward you can scroll before less just repaints the whole screen instead ๐Ÿ’… If you need to go forward more than n lines, it repaints, and -c or -C can repaint from the top if you want that. By default, any forward movement just scrolls โœจ
  • -zn, --window=n, -n โ€” this changes the default scrolling window size to n lines ๐Ÿฆ‹ The default is one full screenful. The z and w commands can change the window size too, and the z can be left off for compatibility with some versions of more(1) ๐ŸŒธ If n is negative, it means n lines less than the current screen size. For example, on a 24-line screen, -z-4 gives you a 20-line window. If the screen gets resized to 40 lines, the window automatically becomes 36 lines. The math is giving โœจ
  • -"cc, --quotes=cc โ€” this changes the filename quoting character ๐ŸŽ€ It might be necessary if you're trying to name a file with both spaces and quote characters, which is a whole mood ๐Ÿ’€ With one character, that character becomes the quote character, and filenames with a space should be wrapped in it instead of double quotes. With two characters, the first becomes the open quote and the second becomes the close quote. Filenames with a space should then be preceded by the open quote and followed by the close quote. Heads up: even after you change the quote characters, this option is still -" (a dash followed by a double quote) ๐Ÿซถ
  • -~, --tilde โ€” normally, lines after the end of the file show up as a single tilde (~) ๐ŸŒ™ With this option, those lines show up as blank lines instead ๐Ÿค
  • -#, --shift โ€” this sets the default number of positions to scroll horizontally with the RIGHTARROW and LEFTARROW commands โžก๏ธ If you set it to zero, the default becomes one half of the screen width. You can also type it as a fraction of the screen width, starting with a decimal point: .5 is half the screen width, .3 is three tenths, and so on ๐Ÿ’– If you use a fraction, the actual number of scroll positions gets recalculated if the terminal window is resized ๐Ÿงš
  • --exit-follow-on-close โ€” when you're using the "F" command on a pipe, less will automatically stop waiting for more data once the input side of the pipe is closed ๐Ÿ‘‘
  • --file-size โ€” if you pass --file-size, less figures out the size of the file right after opening it ๐Ÿ“ Then the "=" command can show you the number of lines in the file ๐Ÿ“ Normally this doesn't happen, because it can be super slow if the input is non-seekable (like a pipe) and it's big ๐Ÿ˜ญ
  • --follow-name โ€” okay so normally, if the input file gets renamed while an F command is running, less keeps showing the contents of the original file even after the name change ๐Ÿ™ˆ With --follow-name, during an F command less will periodically try to reopen the file by name. If the reopen works and the file is different from the original (meaning a new file was created with the same name as the original, now renamed, file), less shows the contents of that new file instead ๐Ÿ”ฅ
  • --header=L,C,N โ€” this sets how many header lines and columns show up on the screen ๐ŸŽ€ The number of header lines is L. If L is 0, header lines are turned off. If L is empty or missing, the number of header lines stays the same. The number of header columns is C. If C is 0, header columns are turned off. If C is empty or missing, the number of header columns stays the same. The first header line is line number N in the file. If N is empty or missing, it's taken to be the number of the line currently showing in the first line of the screen (if you typed the --header command from inside less), or 1 (if the --header option was given on the command line). The special form --header=- turns off header lines and header columns, and it's the same as --header=0,0 ๐Ÿ’…

When L is nonzero, the first L lines at the top of the screen get replaced with the L lines of the file starting at line N, no matter which part of the file you're looking at ๐ŸŒˆ When header lines are showing, any file contents before the header line can't be viewed ๐Ÿ™ˆ When C is nonzero, the first C characters at the start of each line get replaced with the first C characters of the line, even if the rest of the line is scrolled sideways โœจ

  • --incsearch โ€” subsequent search commands become "incremental" ๐Ÿ” That means less jumps to the next line containing the search pattern as you type each character of the pattern ๐Ÿฆ‹
  • --intr=c โ€” uses the character c instead of ^X to interrupt a read when the "Waiting for data" message is showing ๐Ÿ›‘ c has to be an ASCII character, one with a value between 1 and 127 inclusive. A caret followed by a single character can be used to write a control character ๐Ÿงš
  • --line-num-width=n โ€” sets the minimum width of the line number field to n characters when the -N option is in effect ๐Ÿ”ข The default is 7 ๐Ÿ’œ
  • --match-shift=n โ€” when -S is in effect, if a search match isn't visible because it's shifted off to the left or right of the screen, the text shifts horizontally so the match becomes visible ๐ŸŒธ This option picks the column where the first character of the match lands after the shift. In other words, there will be n characters visible to the left of the match ๐Ÿซถ

You can also type this as a fraction of the screen width, starting with a decimal point: .5 is half the screen width, .3 is three tenths, and so on. If you use a fraction, the actual number of scroll positions gets recalculated if the terminal window is resized ๐ŸŽ€

  • --modelines=n โ€” before displaying a file, less reads the first n lines to look for a vim-compatible modeline ๐ŸŒท If n is zero, less doesn't look for modelines at all. With a modeline, the file itself can say which tab stops to use when you view it ๐Ÿ“

A modeline has, 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 isn't used, option settings can be separated by either spaces or colons. The word set is required if the program name is less, but it's optional if any of the other three names are used. If any option setting has the form tabstop=n or ts=n, then tab stops are set automatically, just as if --tabs=n had been given. Check the --tabs description for the acceptable values of n ๐Ÿ“

  • --mouse โ€” enables mouse input ๐Ÿ–ฑ๏ธ Scrolling the mouse wheel down moves forward in the file, scrolling it up moves backward, a left-click sets the "#" mark to the line you clicked, and a right-click (or any other click) returns you to the "#" mark position ๐Ÿฆ‹ If you left-click while the mouse cursor is on an OSC 8 hyperlink, that hyperlink gets selected as if you'd used the ^O^N command ๐Ÿ’œ If you left-click on an OSC 8 hyperlink that's already selected, it gets opened as if you'd used the ^O^O command ๐ŸŒˆ The number of lines to scroll when the wheel moves can be set with the --wheel-lines option. Mouse input only works on terminals that support X11 mouse reporting, and on the Windows version of less ๐Ÿซถ
  • --MOUSE โ€” same as --mouse, except the direction you scroll with the mouse wheel is reversed ๐Ÿ”„
  • --no-keypad โ€” stops less from sending the keypad initialization and deinitialization strings to the terminal โŒจ๏ธ This is sometimes handy if those keypad strings make the numeric keypad act weird ๐Ÿ™„
  • --no-histdups โ€” this changes things so that if you type in a search string or file name that's already in the history list, the old copy gets removed from the history list before the new one is added ๐Ÿ“œ That way, a given string only shows up once in the history list. Normally, a string can show up multiple times ๐Ÿ’…
  • --no-number-headers โ€” header lines (set up with the --header option) don't get line numbers ๐Ÿ”ข Line number 1 goes to the first line after any header lines ๐ŸŒธ
  • --no-search-header-lines โ€” searches skip header lines, but still include header columns ๐Ÿ”
  • --no-search-header-columns โ€” searches skip header columns, but still include header lines ๐Ÿ”
  • --no-search-headers โ€” searches skip both header lines and header columns ๐Ÿ™ˆ
  • --no-vbell โ€” disables the terminal's visual bell ๐Ÿ”•
  • --proc-backspace โ€” if set, backspaces get handled as if neither the -u option nor the -U option were set ๐Ÿง  That means a backspace next to an underscore makes the text show up in underline mode, and a backspace between identical characters makes the text show up in boldface mode ๐Ÿ’€ This option overrides -u and -U, so the display of backspaces can be controlled separately from tabs and carriage returns โœจ If it's not set, backspace display is controlled by the -u and -U options ๐ŸŽ€
  • --PROC-BACKSPACE โ€” if set, backspaces get handled as if the -U option were set, which means backspaces get treated as control characters ๐Ÿšจ

Okay so, the options keep going, bestie ๐Ÿ’…โœจ

  • --proc-return ๐ŸŽ€ โ€” If this is set, carriage returns get treated like neither -u nor -U was set, so a carriage return right before a newline just vanishes ๐Ÿซถ. This one overrides -u and -U, which means you can control carriage return display separately from backspaces and tabs ๐Ÿ’–. If it's not set, the -u and -U options are in charge of carriage returns.
  • --PROC-RETURN ๐Ÿ”ฅ โ€” If this is set, carriage returns act like -U was set. Basically they become control characters, no cap ๐Ÿ’€.
  • --proc-tab ๐Ÿฆ‹ โ€” If this is set, tabs get treated like -U was not set, which means they're expanded into spaces โœจ. This overrides -U, so tab display can be handled separately from backspaces and carriage returns ๐Ÿ’œ. If it's not set, tab display is controlled by the -U options.
  • --PROC-TAB ๐ŸŒธ โ€” If this is set, tabs act like -U was set, so they're treated as control characters. Iconic behavior ๐Ÿ‘‘.
  • --redraw-on-quit ๐Ÿงš โ€” When you quit, after the terminal deinitialization string gets sent, it redraws the entire last screen. This is lowkey essential for terminals whose deinit string switches away from an alternate screen ๐Ÿ˜ญ, because it keeps the last screenful of the current file visible after less quits. Main character moment ๐Ÿ“.
  • --rscroll=c ๐ŸŒˆ โ€” This changes the character used to mark truncated lines. It can start with a two-character attribute indicator, just like LESSBINFMT does ๐Ÿ’…. If there's no attribute indicator, standout gets used. If you set it to "-", truncated lines won't be marked at all ๐Ÿ™ˆ.
  • --save-marks ๐Ÿ’– โ€” Marks get saved in the history file, so they stick around across different invocations of less โœจ. Literally so useful ๐Ÿซถ.
  • --search-options=... ๐Ÿ”ฅ โ€” This sets default search modifiers ๐ŸŽ€. The value is a string with one or more of the characters E, F, K, N, R or W. Setting any of these is the same as typing that control character at the beginning of every search pattern ๐Ÿ’…. For example, --search-options=W is the same as typing ^W at the start of every pattern. The value can also include a digit from 1 to 5, which works the same as typing ^S followed by that digit at the start of every search pattern ๐Ÿฆ‹. The value "-" disables all default search modifiers ๐Ÿ’€.
  • --show-preproc-errors ๐Ÿงš โ€” If a preprocessor produces data but then exits with a non-zero exit code, less will show a warning ๐Ÿ˜ฌ.
  • --status-col-width=n ๐ŸŒธ โ€” This sets the width of the status column when the -J option is in effect ๐Ÿ’œ. The default is 2 characters.
  • --status-line โœจ โ€” If a line is marked, the entire line gets highlighted instead of just the status column ๐Ÿ’–. Lines highlighted because of the -w option will also have the entire line highlighted ๐Ÿ”ฅ. If --use-color is set, the line is colored instead of highlighted ๐ŸŒˆ.
  • --use-backslash ๐Ÿ‘‘ โ€” This changes how the options after it get interpreted ๐Ÿ™ˆ. After --use-backslash, any backslash in an option string gets removed, and the character right after it is taken literally ๐Ÿ’…. That's how you get a dollar sign into option strings, periodt ๐Ÿ’€.
  • --use-color ๐ŸŒˆ โ€” This enables colored text in various places โœจ. You can use the -D option to change the colors ๐ŸŽ€. Heads up though: colored text only works if your terminal supports ANSI color escape sequences (as defined in https://www.ecma-international.org/publications-and-standards/standards/ecma-48) ๐Ÿ˜ญ.
  • --wheel-lines=n ๐Ÿฆ‹ โ€” This sets how many lines to scroll when the mouse wheel moves, but only when the --mouse or --MOUSE option is in effect ๐Ÿซถ. The default is 1 line.
  • --wordwrap ๐Ÿ’œ โ€” When the -S option isn't in use, each line wraps at a space or tab whenever possible, so a word doesn't get split between two lines โœจ. The default is to wrap at any character, which is lowkey messy ๐Ÿ™ˆ.
  • -- ๐Ÿงš โ€” A command line argument of -- marks the end of the option arguments ๐ŸŽ€. Anything after it gets interpreted as a filename ๐Ÿ’…. This is super handy when you want to view a file whose name starts with a - or + ๐Ÿ“.
  • + ๐ŸŒŸ โ€” If a command line option begins with +, the rest of that option is treated as an initial command for less ๐Ÿ’–. For example, +G tells less to start at the end of the file instead of the beginning, and +/xyz tells it to start at the first occurrence of "xyz" in the file ๐Ÿ”ฅ. As a special case, +<number> acts like +<number>g, meaning it starts the display at that line number (but check the caveat under the g command above ๐Ÿ‘€). If the option starts with ++, the initial command applies to every file being viewed, not just the first one ๐Ÿ‘‘. The + command described above can also be used to set or change an initial command for every file ๐ŸŒˆ.

โœจ LINE EDITING โœจ

When you're typing a command line at the bottom of the screen (like a filename for the :e command, or the pattern for a search ๐Ÿ”), you can use certain keys to manipulate that command line ๐Ÿ’…. Most commands have an alternate form in [ brackets ] that you can use if a key doesn't exist on your keyboard ๐Ÿซถ. (Heads up: the forms beginning with ESC don't work on some MS-DOS and Windows systems, because ESC is the line erase character there ๐Ÿ˜ญ.) Any of these special keys can be entered literally by putting the "literal" character in front of it, which is either ^V or ^A ๐ŸŽ€. A backslash can also be entered literally by typing two backslashes ๐Ÿฆ‹.

  • LEFTARROW [ ESC-h ] ๐ŸŒธ โ€” Moves the cursor one space to the left.
  • RIGHTARROW [ ESC-l ] ๐ŸŒธ โ€” Moves the cursor one space to the right.
  • ^LEFTARROW [ ESC-b or ESC-LEFTARROW ] โœจ โ€” (That is, CONTROL and LEFTARROW at the same time ๐Ÿ’–.) Moves the cursor one word to the left.
  • ^RIGHTARROW [ ESC-w or ESC-RIGHTARROW ] โœจ โ€” (That is, CONTROL and RIGHTARROW at the same time ๐Ÿ’–.) Moves the cursor one word to the right.
  • HOME [ ESC-0 ] ๐Ÿ  โ€” Moves the cursor to the beginning of the line ๐Ÿงš.
  • END [ ESC-$ ] ๐Ÿ โ€” Moves the cursor to the end of the line ๐Ÿ’œ.
  • BACKSPACE ๐Ÿ—‘๏ธ โ€” Deletes the character to the left of the cursor, or cancels the command if the command line is empty ๐Ÿ’€.
  • DELETE or [ ESC-x ] ๐Ÿ’… โ€” Deletes the character under the cursor.
  • ^BACKSPACE [ ESC-BACKSPACE ] ๐Ÿ”ฅ โ€” (That is, CONTROL and BACKSPACE at the same time.) Deletes the word to the left of the cursor ๐Ÿซถ.
  • ^DELETE [ ESC-X or ESC-DELETE ] ๐Ÿ”ฅ โ€” (That is, CONTROL and DELETE at the same time.) Deletes the word under the cursor ๐Ÿ˜ญ.
  • UPARROW [ ESC-k ] ๐ŸŒˆ โ€” Retrieves the previous command line โฌ†๏ธ. If you type some text first and then press UPARROW, it'll retrieve the previous command that begins with that text โœจ.
  • DOWNARROW [ ESC-j ] ๐ŸŒˆ โ€” Retrieves the next command line โฌ‡๏ธ. If you type some text first and then press DOWNARROW, it'll retrieve the next command that begins with that text ๐Ÿ’–.
  • TAB ๐ŸŽ€ โ€” Completes the partial filename to the left of the cursor ๐Ÿฆ‹. If it matches more than one filename, the first match goes into the command line ๐ŸŒธ. Pressing TAB again cycles 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) ๐Ÿ“. The environment variable LESSSEPARATOR can be used to specify a different character to append to a directory name ๐Ÿงš.
  • BACKTAB [ ESC-TAB ] ๐ŸŽ€ โ€” Like TAB, but it cycles through the matching filenames in the reverse direction ๐Ÿ”™.
  • ^L ๐Ÿฆ‹ โ€” Completes the partial filename to the left of the cursor ๐Ÿ’…. If it matches more than one filename, all of the matches go into the command line (if they fit) ๐Ÿ’œ.
  • ^U (Unix and OS/2) or ESC (MS-DOS and Windows) ๐Ÿงน โ€” Deletes the entire command line, or cancels the command if the command line is empty ๐Ÿ’€. If you've changed your line-kill character in Unix to something other than ^U, that character gets used instead of ^U ๐Ÿซถ.
  • ^G ๐ŸŒŸ โ€” Deletes the entire command line and returns you to the main prompt ๐Ÿ .

โœจ KEY BINDINGS โœจ

You can define your own less commands by creating a lesskey source file ๐Ÿ”‘. This file specifies a set of command keys and an action for each key ๐Ÿ’–. You can also change the line-editing keys (see LINE EDITING) and set environment variables used by less ๐ŸŽ€. Check out the lesskey(1) manual page for details about the file format ๐Ÿ“–.

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 it. On Unix systems, less looks for a lesskey file called "$XDG_CONFIG_HOME/lesskey" or "$HOME/.config/lesskey" or "$HOME/.lesskey" ๐Ÿง. On MS-DOS and Windows systems, less looks for a lesskey file called "$HOME/_lesskey", and if it's not found there, it looks for a lesskey file called "_lesskey" in any directory specified in the PATH environment variable ๐ŸชŸ. On OS/2 systems, less looks for a lesskey file called "$HOME/lesskey.ini", and if it's not found, it looks for a lesskey file called "lesskey.ini" in any directory specified in the INIT environment variable. If it's not found there either, it looks for a lesskey file called "lesskey.ini" in any directory specified in the PATH environment variable ๐ŸŒˆ.

A system-wide lesskey source file can also be set up to provide key bindings ๐ŸŒ. If a key is defined in both a local lesskey file and the system-wide file, the bindings in the local file take precedence over the system-wide ones ๐Ÿ‘‘. 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 for it. On Unix systems, the system-wide lesskey file is /usr/local/etc/syslesskey. (However, if less was built with a different sysconf directory than /usr/local/etc, that directory is where the syslesskey file gets 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 ๐ŸŒˆ.

Heads up, bestie โš ๏ธ: previous versions of less (before v582) used lesskey files with a binary format, produced by the lesskey program. It's no longer necessary to use the lesskey program ๐Ÿ’€.

โœจ INPUT PREPROCESSOR โœจ

okay so you can set up an "input preprocessor" for less ๐Ÿ’… Before less opens a file, it gives your input preprocessor a chance to change how the file's contents get displayed ๐Ÿฆ‹ The preprocessor is just an executable program (or shell script) that writes the contents of the file into a different file, called the replacement file ๐ŸŒธ less then shows the replacement file's contents instead of the original's. BUT (this is the iconic part) it still looks like you opened the original file, because less shows the original filename as the name of the current file ๐Ÿ™ˆ

An input preprocessor gets one command line argument, the original filename exactly as you typed it ๐ŸŽ€ It should create the replacement file and, once it's done, print the replacement file's name to its standard output โœจ If the preprocessor doesn't output a replacement filename, less just uses the original file like normal ๐Ÿ’– The input preprocessor is never called when you're viewing standard input ๐Ÿ™…โ€โ™€๏ธ To set one up, set the LESSOPEN environment variable to a command line that runs your preprocessor ๐Ÿซถ That command line needs exactly one occurrence of the string "%s", which gets swapped out for the filename when the preprocessor runs.

When less closes a file opened this way, it calls another program, the input postprocessor ๐Ÿงน This is the clean-up crew, so it can do whatever tidying you want (like deleting the replacement file that LESSOPEN made) ๐Ÿ’œ It gets two command line arguments: the original filename as you typed it, and the replacement file's name. To set one up, set the LESSCLOSE environment variable to a command line that runs your postprocessor ๐ŸŒˆ It can include two occurrences of "%s". The first one gets replaced with the original filename, and the second gets replaced with the replacement filename that LESSOPEN output.

For example, on lots of Unix systems, these two scripts let you keep files compressed but still view them straight in less ๐Ÿ“

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 them, put both scripts somewhere they can be executed, then set LESSOPEN="lessopen.sh %s" and LESSCLOSE="lessclose.sh %s %s" ๐Ÿงš Fancier LESSOPEN and LESSCLOSE scripts can be written to handle other types of compressed files, and so on, the sky's the limit ๐Ÿš€

It's also possible to set up an input preprocessor that pipes the file data straight into less, instead of dumping it into a replacement file ๐ŸŒŠ This means you don't have to decompress the whole file before you can start reading it, which is so efficient it's giving ๐Ÿ˜ญ A preprocessor that works this way is called an input pipe. Instead of writing a replacement filename to its standard output, an input pipe writes the entire contents of the replacement to its standard output. If the input pipe doesn't write any characters to its standard output, there's no replacement and less uses the original file, as normal ๐Ÿซ  To use an input pipe, make the very first character of the LESSOPEN environment variable a vertical bar (|) so less knows it's a pipe ๐Ÿ’ซ Same as before, the command string must contain one occurrence of %s, which gets replaced with the input file's filename.

For example, on lots of Unix systems, this script does the same job as the previous example scripts ๐Ÿ’–

lesspipe.sh:

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

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

โš ๏ธ Heads up, bestie: a preprocessor can't output an empty file, because less reads that as "no replacement" and quietly uses the original file ๐Ÿ˜ค To get around this, if LESSOPEN starts with two vertical bars (||), the script's exit status decides what happens when the output is empty ๐Ÿซถ If the output is empty and the exit status is zero, the empty output counts as the replacement text โœ… If the output is empty and the exit status is nonzero, the original file gets used โŒ For compatibility with older versions of less, if LESSOPEN starts with only one vertical bar, the preprocessor's exit status gets ignored ๐Ÿ™ˆ

When you're using an input pipe, a LESSCLOSE postprocessor can be used, but it's usually not necessary since there's no replacement file to clean up ๐Ÿงผ In that case, the replacement filename passed to the LESSCLOSE postprocessor is "-".

For compatibility with older versions of less, the input preprocessor or pipe is not used when less is viewing standard input ๐Ÿ™…โ€โ™€๏ธ BUT, if the first character of LESSOPEN is a dash (-), the input preprocessor gets used on standard input too, as well as on other files ๐ŸŒŸ In this case the dash isn't counted as part of the preprocessor command ๐Ÿ’… When standard input is being viewed, the preprocessor gets passed a filename that's just a single dash. Similarly, if the first two characters of LESSOPEN are a vertical bar and a dash (|-), or two vertical bars and a dash (||-), the input pipe gets used on standard input as well as other files ๐ŸŒธ Again, the dash isn't considered part of the input pipe command ๐Ÿฆ‹

๐ŸŒธ NATIONAL CHARACTER SETS ๐ŸŒธ

okay so there are three kinds of characters floating around in your input file ๐Ÿฆ‹

  • normal characters โ€” these can be shown straight on the screen, no drama ๐Ÿ’–
  • control characters โ€” you shouldn't display these directly, but they're totally expected to show up in regular text files (think backspace and tab) ๐Ÿซถ
  • binary characters โ€” not displayable, and they're not supposed to be hanging out in text files at all ๐Ÿ’€

a "character set" is basically just a cheat sheet that says which characters count as normal, control, or binary โœจ you pick one with the LESSCHARSET environment variable. here are the possible values, bestie ๐Ÿ‘‘

  • ascii โ€” BS, TAB, NL, CR, and formfeed are control characters, anything with a value from 32 to 126 is normal, and everything else is binary ๐ŸŽ€
  • iso8859 โ€” an ISO 8859 character set. it's the same as ASCII, except characters from 160 to 255 get treated as normal ๐ŸŒˆ
  • latin1 โ€” same as iso8859 ๐Ÿ“
  • latin9 โ€” same as iso8859 ๐Ÿ“
  • dos โ€” a character set made for MS-DOS ๐Ÿ’พ
  • ebcdic โ€” an EBCDIC character set ๐Ÿงš
  • IBM-1047 โ€” an EBCDIC character set used by OS/390 Unix Services. it's the EBCDIC cousin of latin1, so you get similar results by setting either LESSCHARSET=IBM-1047 or LC_CTYPE=en_US in your environment ๐Ÿ”ฅ
  • koi8-r โ€” a Russian character set ๐ŸŒธ
  • next โ€” a character set made for NeXT computers ๐Ÿ’œ
  • utf-8 โ€” the UTF-8 encoding of the ISO 10646 character set. this one is special because it supports multi-byte characters in the input file, and it's the only character set that does โœจ
  • windows โ€” a character set made for Microsoft Windows (cp 1252) ๐Ÿฆ‹

in rare cases you might want less to use a character set that isn't in the LESSCHARSET list, and that's where LESSCHARDEF comes in ๐Ÿซถ it should be set to a string where each character represents one character in the set. "." means normal, "c" means control, and "b" means binary, and a decimal number can be used for repetition. so "bccc4b." would mean character 0 is binary, 1, 2 and 3 are control, 4, 5, 6 and 7 are binary, and 8 is normal. everything after the last one is treated the same as the last one, so characters 9 through 255 would be normal. (that's just an example, and it doesn't necessarily match any real character set ๐Ÿ™ˆ)

here's the LESSCHARDEF value that's equivalent to each of the LESSCHARSET values, no cap:

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

okay so, the default-picking situation ๐Ÿ’… if neither LESSCHARSET nor LESSCHARDEF is set, but any of the strings "UTF-8", "UTF8", "utf-8" or "utf8" shows up in the LC_ALL, LC_CTYPE or LANG environment variables, then the default character set is utf-8 ๐ŸŒˆ

if that string isn't there, but your system supports the setlocale interface, less will ask setlocale what character set to use ๐Ÿงš setlocale is controlled by the LANG or LC_CTYPE environment variables.

and if the setlocale interface isn't available either? the default character set is utf-8 โœจ no matter what, you're getting utf-8 as the fallback, periodt ๐Ÿ’–


control and binary characters get shown in standout (reverse video) ๐Ÿ”ฅ each one shows up in caret notation if possible, so like ^A for control-A. caret notation is only used if inverting the 0100 bit gives you a normal printable character. otherwise, the character gets displayed as a hex number in angle brackets ๐Ÿ™ˆ

you can change this format with the LESSBINFMT environment variable ๐ŸŽ€ it can begin with a "*" and one character to pick the display attribute:

  • "*k" โ€” blinking
  • "*d" โ€” bold
  • "*u" โ€” underlined
  • "*s" โ€” standout
  • "*n" โ€” normal

if LESSBINFMT doesn't begin with a "*", the normal attribute is assumed. the rest of LESSBINFMT is a string that can include one printf-style escape sequence (a % followed by x, X, o, d, etc.) ๐Ÿฆ‹ for example, if LESSBINFMT is "*u[%x]", binary characters show up as underlined hexadecimal surrounded by brackets ๐Ÿซถ the default if you don't specify LESSBINFMT is "*s<%02X>".

โš ๏ธ heads up bestie: the result of expanding the character via LESSBINFMT must be less than 31 characters. go over that and it's not gonna be happy ๐Ÿ’€

when the character set is utf-8, the LESSUTFBINFMT environment variable acts like LESSBINFMT but it applies to Unicode code points that were successfully decoded and are still unsuitable for display (like unassigned code points) ๐ŸŒธ its default value is "<U+%04lX>". quick heads up that LESSUTFBINFMT and LESSBINFMT share their display attribute setting ("*x"), so setting one will affect both ๐Ÿ‘‘ LESSUTFBINFMT gets read after LESSBINFMT, so its setting, if it has one, wins the priority fight ๐Ÿ’…

problematic octets in a UTF-8 file get displayed individually using LESSBINFMT, so it's easier to figure out how the UTF-8 file is broken ๐Ÿงš those are: octets of a truncated sequence, octets of a complete but non-shortest form sequence, invalid octets, and stray trailing octets ๐Ÿ˜ญ


when the character set is utf-8, sometimes (rarely!) you might want to override Unicode's idea of what type a certain character is ๐Ÿฆ‹ for example, characters in a Private Use Area are normally treated as control characters. but if you're using a custom font with printable characters in that range, you might want less to treat them as printable ๐ŸŽ€ you do that by setting the LESSUTFCHARDEF environment variable to a comma-separated list of character type definitions โœจ

each character type definition is either one hexadecimal codepoint or a pair of codepoints separated by a dash, followed by a colon and a type character ๐Ÿ’– each hex codepoint can optionally start with a "U" or "U+". if you give a pair, the type gets set for every character inclusively between the two values. if there are multiple comma-separated codepoint values, they have to be in ascending numerical order ๐Ÿ™ˆ the type character can 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 ๐Ÿงš

for example, setting LESSUTFCHARDEF to this:

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

would make all Private Use Area characters be treated as printable ๐Ÿซถโœจ

โœจ PROMPTS โœจ

okay so the -P option lets you totally customize your prompt, bestie ๐Ÿ’… whatever string you give -P replaces the default prompt string. Some characters in there get interpreted in special ways. The prompt system is kinda complicated because it's built for maximum flexibility, but you don't need to understand all of it to make a cute prompt ๐ŸŽ€

A percent sign followed by a single character gets expanded based on that character. (Anywhere you see input file size below, it means the preprocessed size if you're using an input preprocessor ๐Ÿงš)

  • %bX โ€” Gets replaced with the byte offset into the current input file ๐Ÿฆ‹ The b is followed by one character (the X above) that picks which line's offset you want. t means the top line on the display, m means the middle line, b means the bottom line, B means the line right after the bottom line, and j means the "target" line set by the -j option.
  • %B โ€” Gets replaced with the size of the current input file.
  • %c โ€” Gets replaced with the column number of the text in the first column of the screen.
  • %dX โ€” Gets replaced with the page number of a line in the input file. Which line is used depends on the X, same as %b ๐Ÿ“„
  • %D โ€” Gets replaced with the number of pages in the input file. Or, equivalently, the page number of the last line in the input file.
  • %E โ€” Gets replaced with the name of your editor. It comes from the VISUAL environment variable, or the EDITOR environment variable if VISUAL isn't defined. Check out the LESSEDIT discussion below ๐Ÿ’–
  • %f โ€” Gets replaced with the name of the current input file.
  • %F โ€” Gets replaced with the last part of the current input file's name.
  • %g โ€” Gets replaced with the shell-escaped name of the current input file. This is super useful when the expanded string is going into a shell command, like in LESSEDIT ๐Ÿš
  • %i โ€” Gets replaced with the index of the current file in the list of input files.
  • %lX โ€” Gets replaced with the line number of a line in the input file. Again, X picks the line, same as %b ๐ŸŒธ
  • %L โ€” Gets replaced with the line number of the last line in the input file.
  • %m โ€” Gets replaced with the total number of input files.
  • %o โ€” Gets replaced with the URI of the currently selected OSC 8 hyperlink. If no hyperlink is selected, you get a question mark instead. OSC 8 handlers use this, as explained in the ^O^O command description ๐Ÿ”—
  • %pX โ€” Gets replaced with the percent into the current input file, based on byte offsets. The line is picked by X, same as %b.
  • %PX โ€” Gets replaced with the percent into the current input file, based on line numbers. The line is picked by X, same as %b.
  • %s โ€” Exactly the same as %B ๐Ÿ™ˆ
  • %t โ€” Removes any trailing spaces. It's usually placed at the end of the string, but it can go anywhere ๐Ÿงน
  • %T โ€” Normally expands to the word "file". But if you're viewing files through a tags list with the -t option, it expands to the word "tag" ๐Ÿท๏ธ
  • %x โ€” Gets replaced with the name of the next input file in the list.

If something is unknown (like the file size when your input is a pipe), a question mark gets printed instead ๐Ÿ’€

The prompt string can also change depending on certain conditions, and this is the bit that makes it feel so smart โœจ A question mark followed by one character acts like an "IF". Depending on the character after the question mark, a condition gets checked. If it's true, everything after the question mark and condition character, up until a period, gets included in the prompt. If it's false, all of that gets skipped ๐Ÿฆ‹ A colon between the question mark and the period works like an "ELSE": anything between the colon and the period only shows up if the IF condition is false. The condition characters (the ones right after a question mark) can be:

  • ?a โ€” True if anything has been added to the prompt so far.
  • ?bX โ€” True if the byte offset of the specified line is known.
  • ?B โ€” True if the size of the current input file is known.
  • ?c โ€” True if the text is shifted horizontally (%c isn't zero).
  • ?dX โ€” True if the page number of the specified line is known.
  • ?e โ€” True if you're at end-of-file.
  • ?f โ€” True if there's an input filename (aka, your input isn't 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's more than one input file.
  • ?n โ€” True if this is the first prompt in a new input file.
  • ?pX โ€” True if the percent into the current input file, based on byte offsets, for the specified line is known.
  • ?PX โ€” True if the percent into the current input file, based on line numbers, for the specified line is known.
  • ?s โ€” Exactly the same as ?B.
  • ?x โ€” True if there's a next input file (aka, the current file isn't the last one).

Any character that isn't special (question mark, colon, period, percent, or backslash) just shows up in the prompt as-is. If you want one of the special characters to show up literally, put a backslash in front of it ๐Ÿซถ

Some examples, because examples are everything:

?f%f:Standard input.

This prompt prints the filename if it's known. Otherwise it prints the string "Standard input".

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

This prompt prints the filename if it's known. After that it prints the line number if it's known. If the line number isn't known, it prints the percent if that's known. If that isn't known either, it prints the byte offset if known. If none of those work, a dash gets printed. Notice how every question mark has a matching period, and how the % after %pt is included literally because it's escaped with a backslash ๐Ÿ˜ญ

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

This prints the filename if it's the first prompt in a file, followed by the "file N of N" message if there's more than one input file. Then, if you're at end-of-file, it prints "(END)" followed by the name of the next file, if there is one. Last of all, any trailing spaces get trimmed. This is the default prompt ๐Ÿ‘‘ For reference, here are the defaults for the other two prompts (-m and -M respectively). I've split each one into two lines here just so they're easier to read:

?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\%..%t

And here's the default message the = command produces:

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

The prompt expansion stuff gets used for something else too ๐Ÿงš If an environment variable called LESSEDIT is defined, it's the command that runs when you use the v command. The LESSEDIT string gets expanded the same way the prompt strings do. The default value for LESSEDIT is:

%E ?lm+%lm. %g

So this expands to the editor name, then a +, then the line number, then the shell-escaped file name. If your editor doesn't accept the "+linenumber" syntax, or if it has other differences in how it's invoked, you can change the LESSEDIT variable to tweak this default ๐Ÿ’…


๐Ÿ”’ SECURITY ๐Ÿ”’

When the environment variable LESSSECURE is set to 1, less goes into a "secure" mode ๐Ÿ›ก๏ธ In this mode, these features get turned off:

  • edit โ€” the edit command (v)
  • examine โ€” the examine command (:e)
  • glob โ€” metacharacters like * in filenames, and filename completion (TAB, ^L)
  • history โ€” the history file
  • lesskey โ€” using lesskey files (-k and --lesskey-src)
  • lessopen โ€” the input preprocessor (LESSOPEN environment variable)
  • logfile โ€” log files (s and -o)
  • osc8 โ€” opening OSC 8 links (^O^O)
  • pipe โ€” the pipe command (|)
  • shell โ€” the shell and pshell commands (! and #)
  • stop โ€” stopping less with a SIGSTOP signal
  • tags โ€” using tags files (-t)

The LESSSECURE_ALLOW environment variable can be set to a comma-separated list of feature names that get selectively turned back on when LESSSECURE is set ๐Ÿ”“ Each feature name is the first word of each line in the list above. You can shorten a feature name as long as the shortened version is unambiguous. For example, if LESSSECURE=1 and LESSSECURE_ALLOW=hist,edit were set, every feature above would stay disabled except for history files and the edit command ๐ŸŽ€

Heads up: less can also be compiled to be permanently in "secure" mode. In that case, the LESSSECURE and LESSSECURE_ALLOW variables get ignored, so no sneaking around it ๐Ÿ™…โ€โ™€๏ธ

๐Ÿฆ‹ COMPATIBILITY WITH MORE ๐Ÿฆ‹

If the environment variable LESS_IS_MORE is set to 1, or if the program gets invoked through a file link named "more", less behaves (mostly) like the POSIX more(1) command spec ๐ŸŒˆ In this mode, less acts differently in these ways:

The -e option works differently. If -e isn't set, less acts like -e is set. If -e is set, less acts like -E is set ๐Ÿ’œ

The -m option works differently. If -m isn't set, the medium prompt is used, and it gets prefixed with the string "--More--". If -m is set, the short prompt is used โœจ

The -n option acts like the -z option. The normal behavior of -n isn't available in this mode ๐Ÿ™ˆ

The parameter to the -p option is treated as a less command rather than a search pattern ๐Ÿ”

The LESS environment variable gets ignored, and the MORE environment variable gets used in its place ๐Ÿ“

โœจ ENVIRONMENT VARIABLES โœจ

okay so environment variables can be set the normal way in the system environment, OR in a lesskey(1) file ๐Ÿ—๏ธ if there's a clash, the local lesskey file wins, then the system environment, then the system-wide lesskey file. the hierarchy is literally giving ๐Ÿ‘‘

  • COLUMNS โ€” sets how many columns the screen has. It beats the number of columns from TERM. (But if you've got a windowing system that supports TIOCGWINSZ or WIOCGETD, the window system's idea of the screen size wins over LINES and COLUMNS env vars ๐ŸชŸ)
  • EDITOR โ€” the editor you want for the v command โœ๏ธ
  • HOME โ€” your home directory. less uses it to find a lesskey file on Unix and OS/2 systems ๐Ÿ 
  • HOMEDRIVE, HOMEPATH โ€” if HOME isn't set, these two get smooshed together into your home directory. This is only in the Windows version ๐ŸชŸ
  • INIT โ€” your init directory, used to find a lesskey file on OS/2 systems ๐Ÿ’œ
  • LANG โ€” the language, used for figuring out the character set ๐ŸŒ
  • LC_CTYPE โ€” also the language, used for figuring out the character set ๐ŸŒ
  • LESS โ€” options that get passed to less automatically ๐ŸŽ€
  • LESSANSIENDCHARS โ€” the characters that can end an ANSI color escape sequence (default "m") ๐ŸŒˆ
  • LESSANSIMIDCHARS โ€” the characters that can show up between the ESC character and the end character in an ANSI color escape sequence (default "0123456789:;[?!"'#%()*+ ") ๐Ÿ”ข
  • LESSBINFMT โ€” the format used to display non-printable, non-control characters ๐Ÿ‘€
  • LESSCHARDEF โ€” defines a character set ๐Ÿ”ค
  • LESSCHARSET โ€” picks a predefined character set ๐Ÿ“š
  • LESSCLOSE โ€” the command line that invokes the (optional) input-postprocessor ๐Ÿงน
  • LESSECHO โ€” the name of the lessecho program (default "lessecho"). lessecho is needed to expand metacharacters, like * and ?, in filenames on Unix systems ๐Ÿ”
  • LESSEDIT โ€” the editor prototype string (used for the v command). See the discussion under PROMPTS ๐Ÿ“
  • LESSGLOBALTAGS โ€” the name of the command the -t option uses to find global tags. Normally you'd set this to "global" if your system has the global(1) command. If it's not set, global tags just aren't used ๐Ÿท๏ธ
  • LESSHISTFILE โ€” the name of the history file that remembers search commands and shell commands between less sessions. If it's set to "-" or "/dev/null", no history file gets used ๐Ÿ—‚๏ธ The default depends on your OS, 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" ๐Ÿ’ป
  • LESSHISTSIZE โ€” the max number of commands saved in the history file. The default is 100 ๐Ÿ’ฏ
  • LESSKEYIN โ€” the name of the default lesskey source file ๐Ÿ“„
  • LESSKEY โ€” the name of the default lesskey binary file. (Not used if "$LESSKEYIN" exists.) ๐Ÿ”
  • LESSKEY_CONTENT โ€” the value gets parsed like it's the parameter of a --lesskey-content option ๐Ÿงพ
  • LESSKEYIN_SYSTEM โ€” the name of the default system-wide lesskey source file ๐ŸŒ
  • LESSKEY_SYSTEM โ€” the name of the default system-wide lesskey binary file. (Not used if "$LESSKEYIN_SYSTEM" exists.) ๐Ÿ”’
  • LESSMETACHARS โ€” a list of characters the shell considers "metacharacters" ๐Ÿ™…โ€โ™€๏ธ
  • LESSMETAESCAPE โ€” a prefix less adds before each metacharacter in a command sent to the shell. If LESSMETAESCAPE is an empty string, commands containing metacharacters won't be passed to the shell at all ๐Ÿšซ
  • LESSOPEN โ€” the command line that invokes the (optional) input-preprocessor ๐Ÿ› ๏ธ
  • LESSSECURE โ€” runs less in "secure" mode. See the discussion under SECURITY ๐Ÿ›ก๏ธ
  • LESSSECURE_ALLOW โ€” turns on individual features that LESSSECURE normally disables. See the discussion under SECURITY ๐Ÿ”“
  • LESSSEPARATOR โ€” the string added after a directory name during filename completion ๐Ÿ“
  • LESSUTFBINFMT โ€” the format used to display non-printable Unicode code points ๐Ÿ”ฃ
  • LESSUTFCHARDEF โ€” overrides the type of specified Unicode characters ๐ŸŽจ
  • LESS_COLUMNS โ€” sets how many columns the screen has. Unlike COLUMNS, this one beats the system's idea of the screen size, so you can make less use less than the full width. If it's set to a negative number, the columns used become that much less than the actual screen width ๐Ÿ“
  • LESS_LINES โ€” sets how many lines the screen has. Unlike LINES, this one beats the system's idea of the screen size, so you can make less use less than the full height. If it's set to a negative number, the lines used become that much less than the actual screen height. When it's set, less repaints the entire screen on every movement command, so scrolling may be slower ๐Ÿข
  • LESS_DATA_DELAY โ€” how long (in milliseconds) after starting to read input data before the "Waiting for data" message shows up. The default is 4000 (4 seconds) โณ
  • LESS_IS_MORE โ€” makes less emulate the more(1) command ๐ŸŽญ
  • LESS_OSC8_xxx โ€” where xxx is a URI scheme like http or file, this sets an OSC 8 handler for opening OSC 8 links with a URI of that scheme ๐Ÿ”—
  • LESS_OSC8_ANY โ€” sets an OSC 8 handler for opening OSC 8 links that don't have a specific LESS_OSC8_xxx handler for their scheme ๐ŸŒŸ
  • LESS_TERMCAP_xx โ€” where xx is any two characters, this overrides the definition of that termcap capability for the terminal ๐Ÿ–Œ๏ธ
  • LESS_UNSUPPORT โ€” a space-separated list of command line options. These get ignored (with no error message) if they show up on the command line or in the LESS env var. Options listed in LESS_UNSUPPORT can still be changed by the - and -- commands ๐Ÿ™ˆ Each option in LESS_UNSUPPORT is either a dash followed by a single option letter, or two dashes followed by a long option name ๐Ÿงฉ
  • LINES โ€” sets how many lines the screen has. It beats the number of lines from TERM. (But if you've got a windowing system that supports TIOCGWINSZ or WIOCGETD, the window system's idea of the screen size wins over the LINES and COLUMNS env vars ๐ŸชŸ)
  • MORE โ€” options that get passed to less automatically when it's running in more-compatible mode ๐Ÿฟ
  • PATH โ€” the user's search path (used to find a lesskey file on MS-DOS, Windows, and OS/2 systems) ๐Ÿ—บ๏ธ
  • SHELL โ€” the shell used to run the ! command, and also used to expand filenames ๐Ÿš
  • TERM โ€” the type of terminal less is running on ๐Ÿ“บ
  • VISUAL โ€” the name of the editor (used for the v command) ๐ŸŽจ
  • XDG_CONFIG_HOME โ€” a possible location for the lesskey file; see the KEY BINDINGS section ๐Ÿ—ƒ๏ธ
  • XDG_DATA_HOME โ€” a possible location for the history file; see the description of the LESSHISTFILE env var ๐Ÿ“š
  • XDG_STATE_HOME โ€” a possible location for the history file; see the description of the LESSHISTFILE env var ๐ŸŒฑ

โœจ SEE ALSO โœจ

lesskey(1), lessecho(1) ๐Ÿซถ

Copyright (C) 1984-2024 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 regarding 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.

๐Ÿ‘‘ AUTHOR ๐Ÿ‘‘

Mark Nudelman ๐Ÿง‘โ€๐Ÿ’ป

Report bugs at https://github.com/gwsw/less/issues. ๐Ÿ› For more information, see the less homepage at https://greenwoodsoftware.com/less. ๐ŸŒˆ


bestie, that's the whole page! ๐Ÿฆ‹ less Version 668, last touched 06 Oct 2024, man page for LESS(1) ๐Ÿ’… you're officially less-literate now, periodt โœจ

๐Ÿ“ฆ where this page comes from