A long long time ago, several programs understood the command line argument +N
(e.g. +42
) to mean “start at line N” (not “skip N lines”, but “skip N-1 lines”, because the first line is line 1). The oldest trace I can find is in tail
in Unix V7, but I don't know for sure that this is where the usage started. An important program with the same option is more. Other programs that inherited this syntax from more include less, vi, and most other text editors today.
Over time, this syntax was progressively generalized. By 2.8BSD in 1980, more also supported +/PATTERN
to start at the first line containing the specified pattern. By 2.10BSD in 1985, vi supported +COMMAND
to run an arbitrary command on startup, generalizing +/PATTERN
(not all versions of vi support this, and for example POSIX only specifies -c COMMAND
, but it's supported by nvi, Elvis and Vim). The commands are ex commands, i.e. what you can type after :
.
Less also supports the generalized +COMMAND
(I don't know since when, but it was in the 20th century). In the case of +
, it's as if you'd typed the characters as input after less starts, except in the special cases +N
which is equivalent to +g
and +/PATTERN
where you can omit the final Return.
less '+>' /path/to/file
is an example of that usage: execute the command >
(go to the end of the file) after startup. You can also write less +G
since G
and >
are synonyms. You can combine commands, for example less $'+>?foo\r' /path/to/file
to go to the last occurrence of foo
.
Another way to make Less execute commands on startup is to stuff them in the LESS
environment variable: LESS='+>' less /path/to/file
. This is useful if less
is invoked by another program such as man
(example: Reading and searching long man pages).
+>
and ended up clobbering a file – iruvar Apr 07 '14 at 17:11would be "in reverse" to my ears. Also
should be promoted over '+>" since it has the same effect with fewer keystrokes and less danger of file clobbering for neophytes.
– D McKeon Apr 07 '14 at 22:08