less
less: show text a screen at a time.
Synopsis
less [-R] [file]
Description
less shows file (or, with no file or with -, what comes on standard input) one screen at a time. It draws on the terminal’s alternate screen, with the tty in raw mode, and reads its keys from /dev/tty, so the text can come down a pipe. The whole input is read before anything is shown.
Long lines wrap at the terminal’s width; a tab goes to the next multiple of 8 columns, and other control characters show as ^X (the escape that starts a terminal’s sequences as ^[, unless -R lets them through). Rows past the end show as ~. The last row is the prompt: the file’s name on the first screen, (END) on the last, else :.
When standard output is not a terminal, less copies the text to it, as cat(1) does. With no file named and standard input a terminal, it says “Missing filename” and exits 1.
Options
- -R
- Lets color and style sequences (ESC[…m) through to the terminal, taking no room on the screen; a style goes on across a line’s wrap. Searches find the text, not its styles.
Environment
- LESS
- Options, before the command line’s: one with R in it is -R. man(1) sets it to -R for its pager when it isn’t set, as man-db does.
Commands
- q Q
- Quit.
- Space f ^F ^V PageDown
- Forward one screen.
- b ^B PageUp
- Back one screen.
- Enter j e ^N Down
- Forward one line.
- k y ^P Up
- Back one line.
- d ^D
- Forward half a screen.
- u ^U
- Back half a screen.
- g < Home
- Go to the start.
- G > End
- Go to the end.
- /text
- Go to the next line containing text (a plain string, not a pattern), typed at the prompt and ended by Enter. Backspace edits it; Escape, or Backspace on an empty line, cancels. An empty text repeats the last search.
- n
- Repeat the last search forward.
- N
- Repeat the last search backward.
- ^L r
- Draw the screen again.
Other keys are ignored. ^C ends less, restoring the screen and the tty, with status 130.
Exit status
0 on success; 1 if the file cannot be opened or no input was given; 130 if ended by ^C.
Notes
There are no options; a word starting with - other than - itself is taken as a file name. The terminal’s size is read once, at start.
See also
cat(1), head(1), tail(1), man(1)