less

From Gentoo Wiki
Jump to:navigation Jump to:search

less is a pager for displaying text files.

Installation

USE flags

USE flags for sys-apps/less Excellent text file viewer

pcre Add support for Perl Compatible Regular Expressions
test Enable dependencies and/or preparations necessary to run tests (usually controlled by FEATURES=test but can be toggled independently)

Emerge

less is part of the @system set, so is installed by default.

root #emerge --ask sys-apps/less

Configuration

less is configured via various environment variables and files. For detailed information, refer to the less(1) man page.

Variable Description
LESS Command-line options to pass to every invocation of less.
LESSHISTFILE Path to the file in which store a history of commands issued while using less. By default, this file will be one of $XDG_STATE_HOME/lesshst, $HOME/.local/state/lesshst, $XDG_DATA_HOME/lesshst or $HOME/.lesshst.
LESSKEYIN Path to a file containing custom keybinding definitions, as described in the lesskey(1) man page.

Usage

user $less file.txt

To view line n of the input, provide an argument of +n:

user $less +40 file.txt

There are many bindings available for movement within less; refer to the less(1) man page for details. Some basic keybindings:

  • To move line-by-line, use the vi keys (j to move down, k to move up) or the arrow keys.
  • To move down a page, use Space.
  • To jump to the beginning, use g; to jump to the end, use G.

To search for text within less, type /text, followed by Enter. For example, to search for the text "less", type /less Enter; if the text is found after the current position of the cursor, it will be highlighted. To search for the next match, type n. To clear highlighting of matches, type ESCu. Note that search is case-sensitive by default; this can be changed by passing the -I / --IGNORE-CASE option to the less command.

To access a summary of less commands, type h.

To exit less, type q.

By default, input to less is piped through lesspipe(1) before being displayed. lesspipe performs various types of preprocessing, based on the input contents (e.g. if the input is HTML), in order to display them appropriately. To disable this, pass the -L / --no-lessopen option to the less command. Alternatively, a different preprocessor can be specified via the LESSOPEN environment variable.

See also