LinuxDevCenter.com
oreilly.comSafari Books Online.Conferences.





Linux in a Nutshell

This directory of Linux commands is from Linux in a Nutshell, 5th Edition.

Click on any of the 687 commands below to get a description and list of available options. All links in the command summaries point to the online version of the book on Safari Bookshelf.

Buy it now, or read it online on Safari Bookshelf.



less

less [options] [filename]

less is a program for paging through files or other output. It was written in reaction to the perceived primitiveness of more (hence its name). Some commands may be preceded by a number.

Options

-[z] num, --window=num

Set number of lines to scroll to num. Default is one screenful. A negative num sets the number to num lines less than the current number.

+[+] command

Run command on startup. If command is a number, jump to that line. The option ++ applies this command to each file in the command-line list.

-?, --help

Print help screen. Ignore all other options; do not page through file.

-a, --search-screen

When searching, begin after last line displayed. (Default is to search from second line displayed.)

-bbuffers, --buffers=buffers

Use this many buffers for each file (default is 10). Buffers are 1 KB in size.

-c, --clear-screen

Redraw screen from top, not bottom.

-d, --dumb

Suppress dumb-terminal error messages.

-e, --quit-at-eof

Automatically exit after reaching EOF twice.

-f, --force

Force opening of directories and devices; do not print warning when opening binaries.

-g, --hilite-search

Highlight only string found by past search command, not all matching strings.

-hnum, --max-back-scroll=num

Never scroll backward more than num lines at once.

-i, --ignore-case

Make searches case-insensitive, unless the search string contains uppercase letters.

-jnum, --jump-target=num

Position target line on line num of screen. Target line can be the result of a search or a jump. Count lines beginning from 1 (top line). A negative num is counted back from bottom of screen.

-kfile, --lesskey-file=file

Read file to define special key bindings.

-m, --long-prompt

Display more-like prompt, including percent of file read.

-n, --line-numbers

Do not calculate line numbers. Affects -m and -M options and = and v commands (disables passing of line number to editor).

-ofile, --log-file=file

When input is from a pipe, copy output to file as well as to screen. (Prompt for overwrite authority if file exists.)

-ppattern, --pattern=pattern

At startup, search for first occurrence of pattern.

-q, --quiet, --silent

Disable ringing of bell on attempts to scroll past EOF or before beginning of file. Attempt to use visual bell instead.

-r, --raw-control-chars

Display "raw" control characters instead of using ^x notation. This sometimes leads to display problems, which might be fixed by using -R instead.

-s, --squeeze-blank-lines

Print successive blank lines as one line.

-ttag, --tag=tag

Edit file containing tag. Consult ./tags (constructed by ctags).

-u, --underline-special

Treat backspaces and carriage returns as printable input.

-w, --hilite-unread

Show the line to which a movement command has skipped, phrases displayed by a search command, or the first unread line during a normal scroll by highlighting text in reverse video.

-x n, --tabs=n

Set tab stops to every n characters. Default is 8.

-y n, --max-forw-scroll=n

Never scroll forward more than n lines at once.

-B, --auto-buffers

Do not automatically allocate buffers for data read from a pipe. If -b specifies a number of buffers, allocate that many. If necessary, allow information from previous screens to be lost.

-C, --CLEAR-SCREEN

Redraw screen by clearing it and then redrawing from top.

-E, --QUIT-AT-EOF

Automatically exit after reaching EOF once.

-F, --quit-if-one-screen

Exit without displaying anything if first file can fit on a single screen.

-G, --HILITE-SEARCH

Never highlight matching search strings.

-I, --IGNORE-CASE

Make searches case-insensitive, even when the search string contains uppercase letters.

-J, --status-column

Used with -w or -W, highlight a single column on the left edge of the screen instead of the whole text of an unread line.

-K charset

Use the specified charset.

-M

Prompt more verbosely than with -m, including percentage, line number, and total lines.

-N, --LINE-NUMBERS

Print line number before each line.

-O file, --LOG-FILE=file

Similar to -o, but do not prompt when overwriting file.

-P[mM=] prompt

Set the prompt displayed by less at the bottom of each screen to prompt. The m sets the prompt invoked by the -m option, the M sets the prompt invoked by the -M option, and the = sets the prompt invoked by the = command. Special characters (described in the manpage for less), can be used to print statistics and other information in these prompts.

-Q, --QUIET, --SILENT

Never ring terminal bell.

-R, --RAW-CONTROL-CHARS

Like r, but adjust screen to account for presence of control characters.

-S, --chop-long-lines

Cut, do not fold, long lines.

-T file, --tag-file=file

With the -t option or :t command, read file instead of ./tags.

-U, --UNDERLINE-SPECIAL

Treat backspaces and carriage returns as control characters.

-V, --version

Display version and exit.

-W, --HILITE-UNREAD

Show phrases displayed by a search command, or the first unread line of any forward movement that is more than one line, by highlighting text in reverse video.

-X, --no-init

Do not send initialization and deinitialization strings from termcap to terminal.

Commands

Many commands can be preceded by a numeric argument, referred to as number in the command descriptions.

SPACE,^V,f,^F

Scroll forward the default number of lines (usually one windowful).

z

Similar to SPACE, but allows the number of lines to be specified, in which case it resets the default to that number.

RETURN,^N,e,^E,j,^J

Scroll forward. Default is one line. Display all lines, even if the default is more lines than the screen size.

d,^D,PageDown

Scroll forward. Default is one-half the screen size. The number of lines may be specified, in which case the default is reset.

b,^B,ESC-v

Scroll backward. Default is one windowful.

w

Like b, but allows the number of lines to be specified, in which case it resets the default to that number.

y,^Y,^P,k,^K

Scroll backward. Default is one line. Display all lines, even if the default is more lines than the screen size.

u,^U,PageUp

Scroll backward. Default is one-half the screen size. The number of lines may be specified, in which case the default is reset.

r,^R,^L

Redraw screen.

R

Like r, but discard buffered input.

F

Scroll forward. When an EOF is reached, continue trying to find more output, behaving similarly to tail -f.

g,<,ESC-<

Skip to a line. Default is 1.

G,>,ESC->

Skip to a line. Default is the last line.

p,%

Skip to a position number percent of the way into the file.

{

If the top line on the screen includes a {, find its matching }. If the top line contains multiple {s, use number to determine which one to use in finding a match.

}

If the bottom line on the screen includes a }, find its matching {. If the bottom line contains multiple }s, use number to determine which one to use in finding a match.

(

If the top line on the screen includes a (, find its matching ). If the top line contains multiple (s, use number to determine which one to use in finding a match.

)

If the bottom line on the screen includes a ), find its matching (. If the bottom line contains multiple )s, use number to determine which one to use in finding a match.

[

If the top line on the screen includes a [, find its matching ] . If the top line contains multiple [s, use number to determine which one to use in finding a match.

]

If the bottom line on the screen includes a ] , find its matching [. If the bottom line contains multiple ] s, use number to determine which one to use in finding a match.

ESC-^F

Behave like { but prompt for two characters, which it substitutes for { and } in its search.

ESC-^B

Behave like } but prompt for two characters, which it substitutes for { and } in its search.

m

Prompt for a lowercase letter and then use that letter to mark the current position.

' (single apostrophe)

Prompt for a lowercase letter and then go to the position marked by that letter. There are some special characters:

^

Beginning of file.

$

End of file.

^X^X

Same as '.

/pattern

Find next occurrence of pattern, starting at second line displayed. Some special characters can be entered before pattern:

!

Find lines that do not contain pattern.

*

If current file does not contain pattern, continue through the rest of the files in the command-line list.

@

Search from the first line in the first file specified on the command line, no matter what the screen currently displays.

?pattern

Search backward, beginning at the line before the top line. Treats !, *, and @ as special characters when they begin pattern, as / does.

ESC-/pattern

Same as /*.

ESC-?pattern

Same as ?*.

n

Repeat last pattern search.

N

Repeat last pattern search in the reverse direction.

ESC-n

Repeat previous search command, but as though it were prefaced by *.

ESC-N

Repeat previous search command, but as though it were prefaced by * and in the reverse direction.

ESC-u

Toggle search highlighting.

:e [filename]

Read in filename and insert it into the command-line list of filenames. Without filename, reread the current file. filename may contain special characters:

%

Name of current file.

#

Name of previous file.

^X^V,E

Same as :e.

:n

Read in next file in command-line list.

:p

Read in previous file in command-line list.

:x

Read in first file in command-line list.

:f, =,^G

Print filename, position in command-line list, line number on top of window, total lines, byte number, and total bytes.

- (single dash)

Expects to be followed by a command-line option letter. Toggle the value of that option or, if appropriate, prompt for its new value.

-+

Expects to be followed by a command-line option letter. Reset that option to its default.

--

Expects to be followed by a command-line option letter. Reset that option to the opposite of its default, where the opposite can be determined.

_ (underscore)

Expects to be followed by a command-line option letter. Display that option's current setting.

+command

Execute command each time a new file is read in.

q,:q,:Q,ZZ

Exit.

v

Not valid for all versions. Invoke editor specified by $VISUAL or $EDITOR, or vi if neither is set.

! [command]

Not valid for all versions. Invoke $SHELL or sh. If command is given, run it and then exit. Special characters:

%

Name of current file.

#

Name of previous file.

!!

Last shell command.

| mark-letter command

Not valid for all versions. Pipe fragment of file (from first line on screen to mark-letter) to command. mark-letter may also be:

^

Beginning of file.

$

End of file.

.,newline

Current screen is piped.

Prompts

The prompt interprets certain sequences specially. Those beginning with % are always evaluated. Those beginning with ? are evaluated if certain conditions are true. Some prompts determine the position of particular lines on the screen. These sequences require that a method of determining that line be specified. See the -P option and the manpage for more information.