Commands tagged less (30)

  • Add the followin to ~/.bashrc #colour export LESS_TERMCAP_mb=$'\E[01;31m' export LESS_TERMCAP_md=$'\E[01;37m' export LESS_TERMCAP_me=$'\E[0m' export LESS_TERMCAP_se=$'\E[0m' export LESS_TERMCAP_so=$'\E[01;44;33m' export LESS_TERMCAP_ue=$'\E[0m' export LESS_TERMCAP_us=$'\E[01;32m'


    15
    echo "export LESS_TERMCAP_mb=$'\E[01;31m'" >> ~/.bashrc
    totti · 2011-10-20 17:34:14 8
  • The "pstree" command uses special line-drawing characters. However, when piped into the "less" pager, these are normally disabled.


    7
    pstree -Gap | less -r
    mbirk · 2009-05-21 05:15:16 5

  • 7
    tree -C | less -R
    rkulla · 2010-04-14 00:19:30 4
  • Example : LC_ALL=C man less | less +/ppattern


    6
    man <COMMAND> | less +'/pattern'
    sputnick · 2010-01-26 20:50:00 3
  • SH

    cat mod_log_config.c | shmore or shmore < mod_log_config.c Most pagers like less, more, most, and others require additional processes to be loaded, additional cpu time used, and if that wasn't bad enough, most of them modify the output in ways that can be undesirable. What I wanted was a "more" pager that was basically the same as running: cat file Without modifying the output and without additional processes being created, cpu used, etc. Normally if you want to scroll the output of cat file without modifying the output I would have to scroll back my terminal or screen buffer because less modifies the output. After looking over many examples ranging from builtin cat functions created for csh, zsh, ksh, sh, and bash from the 80's, 90s, and more recent examples shipped with bash 4, and after much trial and error, I finally came up with something that satisifed my objective. It automatically adjusts to the size of your terminal window by using the LINES variable (or 80 lines if that is empty) so This is a great function that will work as long as your shell works, so it will work just find if you are booted in single user mode and your /usr/bin directory is missing (where less and other pagers can be). Using builtins like this is fantastic and is comparable to how busybox works, as long as your shell works this will work. One caveat/note: I always have access to a color terminal, and I always setup both the termcap and the terminfo packages for color terminals (and/or ncurses and slang), so for that reason I stuck the tput setab 4; tput setaf 7 command at the beginning of the function, so it only runs 1 time, and that causes the -- SHMore -- prompt to have a blue background and bright white text. This is one of hundreds of functions I have in my http://www.askapache.com/linux-unix/bash_profile-functions-advanced-shell.html">.bash_profile at http://www.askapache.com/">AskApache.com, but actually won't be included till the next update. If you can improve this in any way at all please let me know, I would be very grateful! ( Like one thing I want is to be able to continue to the next screen by pressing any key instead of now having to press enter to continue) Show Sample Output


    6
    shmore(){ local l L M="`echo;tput setab 4&&tput setaf 7` --- SHMore --- `tput sgr0`";L=2;while read l;do echo "${l}";((L++));[[ "$L" == "${LINES:-80}" ]]&&{ L=2;read -p"$M" -u1;echo;};done;}
    AskApache · 2010-04-21 00:40:37 30
  • Although less behaves more or less like vim in certain aspects, the vim regex for word boundaries (\< and \>) do not work in less. Instead, use \b to denote a word boundary. Therefore, if you want to search for, say, the word "exit", but do not want to search for exiting, exits, etc., then surround "exit" with \b. This is useful if you need to search for specific occurrences of a keyword or command. \b can also be used at just the beginning and end, if needed.


    5
    \bTERM\b
    kFiddle · 2009-04-11 22:05:12 6
  • This makes GNU info output menu items recursively and pipe its contents to less, allowing one to use GNU info in a manner similar to 'man'.


    4
    info --subnodes -o - <item> | less
    EvanTeitelman · 2013-06-11 01:23:23 8
  • Probably will not work very well with scanned documents.


    4
    curl 'LINK' | pdftotext - - | less
    snipertyler · 2014-06-21 00:47:02 6
  • using mb it's still readable;) a symbol variation $ du -ms {,.[^.]}* | sort -nk1 Show Sample Output


    3
    du -ms * .[^.]*| sort -nk1
    ioggstream · 2009-07-01 13:38:13 8

  • 3
    less -XF
    EvanTeitelman · 2013-06-11 01:21:38 7
  • It allows customizing by means of lesspipe. You need to write a ~/.lessfilter script and put this into your ~/.bashrc: eval $(lesspipe) export LESS=-r


    2
    less -r <some file>
    prayer · 2009-03-01 21:19:53 6

  • 2
    du -ms * | sort -nk1
    Tekhne · 2009-07-08 22:11:50 25
  • Show all commands having the part known by you. Eg: apropos pdf | less Show Sample Output


    2
    apropos <part_rember> | less
    totti · 2011-08-19 19:34:57 6
  • Really useful way to combine less and grep while browsing log files. I can't figure out how to make it into a true oneliner so paste it into a script file called lgrep: Usage: lgrep searchfor file1 [file2 file3] Advanced example (grep for an Exception in logfiles that starts with qc): lgrep Exception $(find . -name "qc*.log") Show Sample Output


    1
    argv=("$@"); rest=${argv[@]:1}; less -JMN +"/$1" `grep -l $1 $rest`
    lassel · 2009-10-16 17:36:16 3
  • I like man pages, and I like using `less(1)` as my pager. However, most GNU software keeps the manual in the 'GNU Texinfo' format, and I'm not a fan of the info(1) interface. Just give me less. This command will print out the info(1) pages, using the familiar interface of less! Show Sample Output


    1
    info gpg |less
    StefanLasiewski · 2010-07-01 23:44:15 6
  • This is a simple bash function and a key binding that uses commandlinefu's simple and easy search API. It prompts for a search term, then it uses curl to search commandline fu, and highlights the search results with less.


    1
    function ds { echo -n "search : "; read ST; EST=`php -r "echo rawurlencode('$ST');"`; B64=`echo -n $ST| openssl enc -base64`; curl -s "http://www.commandlinefu.com/commands/matching/$EST/$B64/plaintext" | less -p "$ST"; } ; bind '"\C-k"':"\"ds\C-m\""
    cparker · 2011-02-20 23:46:16 32
  • # s = combine multiple lines of whitespace into 1 # x4 = set the tabstop to 4 instead of 8 # F = Exit if the output fits on 1 screen. This is similar to git diff # R = Raw control chars. This allows you to pipe colordiff straight to less. ie: alias sdi="svn diff | colordiff | less" # S = Chop off long lines # X = Dont send termcap init and deinit scrings to the terminal


    1
    export LESS='-x4FRSXs'
    SEJeff · 2012-05-25 16:46:15 8

  • 1
    pygmentize -l pytb myapp.log | less -SR
    manuq · 2013-01-10 03:13:41 4
  • Alternative1 (grep support): pacman -Ss python | paste - - | grep --color=always -e '/python' | less -R Alternative2 (eye-candy, no grep): pacman --color=always -Ss "python" | paste - - | less -R in ~/.bashrc: pkg-grep() { pacman -Ss "$1" | paste - - | grep --color=always -e "${2:-$1}" | less -R ; } pkg-search() { pacman --color=always -Ss "python" | paste - - | less -R; } Show Sample Output


    1
    pacman -Ss python | paste - - | grep --color=always -e '/python' | less -R
    hute37 · 2016-01-25 14:29:31 12
  • As odd as this may be, I know of servers where the man(1) command is not installed, and there is not enough room on / to install it. However, zcat(1), nroff(1) and less(1) are. This is a way to read those documents without the proper tool to do so, as sad as this may seem. :)


    0
    zcat /usr/share/man/man1/man.1.gz | nroff -man | less
    atoponce · 2011-09-07 01:13:57 3

  • 0
    grep --color=always -nr 'setLevel' --include=*py | less -SRqg
    manuq · 2013-01-10 03:10:10 8
  • This command is similar to the above, but is much simpler to remember. Sure, it's isn't as precise as the parent command, but most people aren't going to remember those --flags anyways unless you stick it into your .bashrc on every single system that you manage. Show Sample Output


    0
    info foo |less
    StefanLasiewski · 2013-09-12 16:49:08 7
  • Don't want to open up an editor just to view a bunch of XML files in an easy to read format? Now you can do it from the comfort of your own command line! :-) This creates a new function, xmlpager, which shows an XML file in its entirety, but with the actual content (non-tag text) highlighted. It does this by setting the foreground to color #4 (red) after every tag and resets it before the next tag. (Hint: try `tput bold` as an alternative). I use 'xmlindent' to neatly reflow and indent the text, but, of course, that's optional. If you don't have xmlindent, just replace it with 'cat'. Additionally, this example shows piping into the optional 'less' pager; note the -r option which allows raw escape codes to be passed to the terminal. Show Sample Output


    0
    xmlpager() { xmlindent "$@" | awk '{gsub(">",">'`tput setf 4`'"); gsub("<","'`tput sgr0`'<"); print;} END {print "'`tput sgr0`'"}' | less -r; }
    hackerb9 · 2015-07-12 09:22:10 11

  • 0
    man -a --regex "byobu" |grep --color=always -i3P 'key[a-z-]*?s' | less -R
    VoidDroid · 2015-10-18 10:38:01 10
  • I've shortened it to: lsc PATH | l ... by adding ... alias lsc="ls --color" ... and ... alias l="less -R" ... to my ~/.bashrc file


    0
    ls --color PATH | less -R
    kevjonesin · 2016-03-07 13:46:02 13
  •  1 2 > 

What's this?

commandlinefu.com is the place to record those command-line gems that you return to again and again. That way others can gain from your CLI wisdom and you from theirs too. All commands can be commented on, discussed and voted up or down.

Share Your Commands


Check These Out

get some information about the parent process from a given process

most used commands in history (comprehensive)
Most of the "most used commands" approaches does not consider pipes and other complexities. This approach considers pipes, process substitution by backticks or $() and multiple commands separated by ; Perl regular expression breaks up each line using | or < ( or ; or ` or $( and picks the first word (excluding "do" in case of for loops) note: if you are using lots of perl one-liners, the perl commands will be counted as well in this approach, since semicolon is used as a separator

check open ports without netstat or lsof

Find the package that installed a command

Generate a random password 30 characters long

Generate a random left-hand password
Generates a random 8-character password that can be typed using only the left hand on a QWERTY keyboard. Useful to avoid taking your hand off of the mouse, especially if your username is left-handed. Change the 8 to your length of choice, add or remove characters from the list based on your preferences or kezboard layout, etc.

Extract tarball from internet without local saving

Get all files of particular type (say, PDF) listed on some wegpage (say, example.com)
See man wget if you want linked files and not only those hosted on the website.

Swap a file or dir with quick resotre
This lets you replace a file or directory and quickly revert if something goes wrong. For example, the current version of a website's files are in public_html. Put a new version of the site in public_html~ and execute the command. The names are swapped. If anything goes wrong, execute it again (up arrow or !!).

Outputs a 10-digit random number


Stay in the loop…

Follow the Tweets.

Every new command is wrapped in a tweet and posted to Twitter. Following the stream is a great way of staying abreast of the latest commands. For the more discerning, there are Twitter accounts for commands that get a minimum of 3 and 10 votes - that way only the great commands get tweeted.

» http://twitter.com/commandlinefu
» http://twitter.com/commandlinefu3
» http://twitter.com/commandlinefu10

Subscribe to the feeds.

Use your favourite RSS aggregator to stay in touch with the latest commands. There are feeds mirroring the 3 Twitter streams as well as for virtually every other subset (users, tags, functions,…):

Subscribe to the feed for: