function mg(){ man ${1} | egrep ${2} | more; }

Fewer keystrokes to search man page of command

Quicker way to search man pages of command for key word
Sample Output
e.g. mg mplayer playlist

mplayer [options] [file|URL|playlist|-]
                   Go backward/forward in the playlist.
                   Go forward in the playlist, even over the end.
              INS and DEL (ASX playlist only)
                   Open playlist.
              Enqueue files given on the command line in the playlist  instead
              playlist or intend to read from stdin later on via the  loadfile
       -playlist <filename>
              Play  files  according to a playlist file (ASX, Winamp, SMIL, or
              it will apply only to the elements of this playlist.
              GUI playlist

By: quincymd
2010-07-01 21:14:24

These Might Interest You

  • Nothing special about hashing here, only the use of cut, I think, could result at fewer keystrokes. Show Sample Output

    echo -n "String to MD5" | md5sum | cut -f1 -d' '
    xakon · 2011-03-05 03:53:09 1
  • What this does is, if I type ?ssh ? then hit the page-up key, it will complete the line to the last time in my history file that I typed ssh. Hitting page up again will go to the 2nd to last time I typed it. Incredibly handy if you ever type the same commands more than once. credit goes to echo "\"\e[6~\": history-search-forward" >> ~/.inputrc

    echo "\"\e[5~\": history-search-backward" >> ~/.inputrc
    silbermm · 2009-03-10 15:32:52 6
  • Will highlight search term i.e. "foo" across entire man page (scroll up or down to see) /term_to_search_for+Enter That is how to find things ;) /Enter (slash+empty string+Enter) will jump to the next occurence of previous searched item.

    knoppix5 · 2013-10-09 08:40:06 2
  • Manpages, command summaries, and pretty much everything else usually have the information you're most likely to want at the beginning. Seeing just the last 40 or so lines of options from a command that has 100 is not super useful, and having to scroll up each time you want to glance at something is spastic. Run this and then do something like p do vi --help and you'll get the first screen(-mostly-)full of vi's usage info and options list Then use p d to page down, and p u to page up. To see the current page again: p r Also useful for situations like p do aptitude search ~dsmorgasbord p next #p sudo aptitude -r install libwickedawesome-perl-snoochieboochies p next p sudo aptitude -r install libwickedawesome-perl-snoochieboochies snazztasticorama-dev-v0.&#8734; where you're using readline up-arrow, HOME, END, etc., to quickly recall commented commands. For the unaware, that option to aptitude search will bring up all of the packages whose descriptions contain the string "smorgasbord". Depending on your distro, there could potentially be hundreds of them.

    p() { l=$LINES; case $1 in do) shift; IFS=$'\n' _pg=( $("$@") ) && _pgn=0 && p r;; r) echo "${_pg[*]:_pgn:$((l-4))}";; d) (( _pgn+=l-4 )); (( _pgn=_pgn>=${#_pg[@]}?${#_pg[@]}-l+4:_pgn )); p r;; u) (( _pgn=_pgn<=l-4?0:_pgn-$l-4 )); p r;; esac; }
    intuited · 2009-12-18 23:35:53 3
  • This microscript looks up a man page for each word possible, and if the correct page is not found, uses w3m and Google's "I'm feeling lucky" to output a first possible result. This script was made as a result of an idea on a popular Linux forum, where users often send other people to RTFM by saying something like "man backup" or "man ubuntu one". To make this script replace the usual man command, save it as "" in your home folder and add the following string to the end of your .bashrc file: alias man='~/' Show Sample Output

    /usr/bin/man $* || w3m -dump"$*"\&btnI | less
    d1337r · 2010-10-05 13:51:39 0
  • Once issuing the command, hit "esc" and then "k" (not together) to enter the search mode at the shell prompt (each time), and invoke the search with "/" as if you would in vi. Type a command and see the most recently used instance of that command. Use "n" and "N" to go forward and backwards through other instances of that command.

    set -o vi
    andykazmaier · 2009-12-22 20:40:10 3

What do you think?

Any thoughts on this command? Does it work on your machine? Can you do the same thing with only 14 characters?

You must be signed in to comment.

What's this? 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

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.


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: