posted on 2014-12-01 07:46:36
Being the default pager on linux, and thus the tool you use to look manpages at usually,
less is worth some more attention.
Unlike editors or IDE's (vi, emacs, nano, eclipse), pagers (at least less) do not have to load a file completely into memory and thus are faster when displaying huge files.
If you happen to think you will never have to open files bigger than some KB size, what about some error logs? (Once I saw a machine write like one additional GB per minute. In this case, you should maybe refrain from
less and just use like
Also, compared to
less can also scroll backwards. (!!!)
Pagers cannot edit text. That's what editors are for.
q quit h show help = or ctrl-g show current file name r redraw screen s save file (if input comes from a pipe, not a file) v edit file with $VISUAL or $EDITOR !<command> execute <command> in $SHELL !<mark><command> pipe text contents between cursor and <mark> to <command>
f or ctrl-f or space move forward one page b or ctrl-b move backward one page g top of first page G bottom of last page <count>p go to <count> percent line in text d forward half a page u backward half a page m<char> mark line with <char> '<char> jump to mark <char>o '' goto previous position
/<pattern> search forward for <pattern> ?<pattern> search backward for <pattern> n next match N previous match ! or ^N prior to <pattern>, will search for non-matching lines ^K prior to <pattern>, just mark lines but don't move cursor ^R don't use regexes for searching &<pattern> SHOW ONLY MATCHES (about the best less command ever)
| hotkey might be interesting.
To pipe the complete buffer content into a file, do this:
1. g (go to top of file) 2. | (start pipe) 3. $ (pipe until the end of buffer) 4. tee [name of logfile].log
Afterwards you should have a new file. This works both with piped input as well as opened files.
All options with dashes can be used while running less, or as startup commands.
+F same as 'tail -f', but with less +/<pattern> open file at <pattern>
+ is needed during startup, from within less its not needed except when you want to reset a option to its default value.
-A search starts after target line -g highlight last search result -G highlight search results -I completely case insensitive searching -i smartcase: case-insensitive if search string contains no upper case -J show status column (to mark lines with search results) left of the the text, lines with matches are marked. F 'Waiting for data... (interrupt to abort)' (means ^C) This is basically a 'tail -f' on stereoids!
`-` prior sets / changes the option `_` just shows it's current state -e quit at EOF -M toggle long prompt (filename, lines, line %) -m toggle medium prompt (line %) -N show line numbers -Q quiet all terminal bells (!!!) -R output raw control chars = SHOW COLORS -s squeeze multiple blank lines into one -S don't wrap long lines -P define custom promtps See last section here about further information.
%bX Replaced by the byte offset into the current input file. The b is followed by a single character (shown as X above) which specifies the line whose byte offset is to be used. If the character is a "t", the byte offset of the top line in the display is used, an "m" means use the middle line, a "b" means use the bottom line, a "B" means use the line just after the bottom line, and a "j" means use the "target" line, as specified by the -j option. %B Replaced by the size of the current input file. %c Replaced by the column number of the text appearing in the first column of the screen. %dX Replaced by the page number of a line in the input file. The line to be used is determined by the X, as with the %b option. %D Replaced by the number of pages in the input file, or quivalently, the page number of the last line in the input file. %E Replaced by the name of the editor (from the VISUAL environment variable, or the EDITOR environment variable if VISUAL is not defined). See the discussion of the LESSEDIT feature below. %f Replaced by the name of the current input file. %F Replaced by the last component of the name of the current input file. %i Replaced by the index of the current file in the list of input files. %lX Replaced by the line number of a line in the input file. The line to be used is determined by the X, as with the %b option. %L Replaced by the line number of the last line in the input file. %m Replaced by the total number of input files. %pX Replaced by the percent into the current input file, based on byte offsets. The line used is determined by the X as with the %b option. %PX Replaced by the percent into the current input file, based on line numbers. The line used is determined by the X as with the %b option. %s Same as %B. %t Causes any trailing spaces to be removed. Usually used at the end of the string, but may appear anywhere. %x Replaced by the name of the next input file in the list.
posted on 2014-08-08 23:44:09
This works on debian:
$ apt-get install source-highlight -y $ export LESSOPEN="| /usr/share/source-highlight/src-hilite-lesspipe.sh %s" $ export LESS=' -R '
export lines into your .bashrc to make them stick.
View posts from 2017-04, 2017-03, 2017-02, 2017-01, 2016-12, 2016-11, 2016-10, 2016-09, 2016-08, 2016-07, 2016-06, 2016-05, 2016-04, 2016-03, 2016-02, 2016-01, 2015-12, 2015-11, 2015-10, 2015-09, 2015-08, 2015-07, 2015-06, 2015-05, 2015-04, 2015-03, 2015-02, 2015-01, 2014-12, 2014-11, 2014-10, 2014-09, 2014-08, 2014-07, 2014-06, 2014-05, 2014-04, 2014-03, 2014-01, 2013-12, 2013-11, 2013-10