24

If I want to know the meaning of wget -b, I see the manual by man wget, then search the -b option.

   -b
   --background
       Go to background immediately after startup.  If no output file is specified via the -o, output is redirected to wget-log.

I want to get the result by a command like man wget -b. (Of course this doesn't work.)

Is there a similar way to make it possible?

  • wget -h | grep '\-b' – Faheem Mitha Jan 23 '15 at 14:29
5

You could redirect the manpage to awk and extact the part:

man wget | awk '/^ *-b *.*$/,/^$/{print}'
       -b
       --background
           Go to background immediately after startup.  If no output file is specified via the -o, output is redirected to wget-log.

That part is everything that is between a -b and an empty line.

  • 1
    {print} can be omitted – Costas Jan 23 '15 at 14:45
  • Thanks, I tried to use with GNU Awk 4.0.1(Ubuntu), GNU Awk 3.1.7(CentOS) and awk version 20070501(OS X), but works only with 4.0.1. – ironsand Jan 23 '15 at 19:10
  • 1
    .*$ can be omitted too – Walter Tross Jan 29 '15 at 22:13
22

If you use less as pager for man you can try

LESS="+/^\s+-b" man wget

where

  1. + symbol to execute next operation after less has opened
  2. / command to start search
  3. ^\s+-b regexp to match -b from start of line

So if you like you can arrange the apropriate function for shell

function rman {
#USAGE: rman programm.name option.to.search (with "-" symbol)
LESS="+/^\s+$2" man "$1"
}

and add it into ~/.bashrc for example.

  • This doesn't work for me, I think because it will not do multiline matching – rb612 Jun 17 '18 at 7:30
13

When you run man command you can press / and then enter the plain text to search for. For example, type /-b and it'll jump to the first instance of -b in the text.

  • 4
    And then n goes to the next instance. – drewbenn Jan 24 '15 at 6:13
  • @drewbenn Oh, nice. I've always just pressed /+enter to continue on. – fluffy Jan 25 '15 at 20:27
10

I wrote a small script to do this called he, e.g. he wget -b.

The basic strategy is: search for the option (e.g. -b) as the first word on a line, then print until the next header, or next line with matching indentation.

If you can't use that, you can get something similar using basic sed, e.g.

man wget | sed -ne '/^  *-b/,/^$/p'
  • Also your desc script is very helpful. – Pandya Oct 4 '14 at 7:07
  • Just decided to rename it to he, as in short help, plus he/man. – Mikel Oct 4 '14 at 7:19
  • Updated to work with the new example, wget -b. – Mikel Jan 26 '15 at 7:59
3

I use the following script that connects to explainshell.com. I copied it from reddit some time ago:

#!/bin/bash
cmd=$1
shift
args=$*
args=${args/ /+}
w3m -dump "http://explainshell.com/explain/$cmd?args=$args"

I named it rman and put it in my $PATH. Usage for wget -b:

$ rman wget -b    
[logo]

  • about
  •
  • [                    ]

wget(1) -b

The non-interactive network downloader

-b
--background
    Go to background immediately after startup.  If no output file is specified via the -o, output is
    redirected to wget-log.

source manpages: wget

You can tweak this script a little to not to show garbage at the beginning.

EDIT: I got it from here. Thanks to the author!

  • 3
    It's important to note that this potentially documents a different implementation/version of the commands from those installed on the machine. – Stéphane Chazelas Jan 23 '15 at 14:11
  • Also, there's no escaping and bad quoting in the code. – l0b0 Jan 23 '15 at 14:16
  • Yes, I wondered if I should emphasize that. However, if a particular option means something in one flavor of the program it usually means the same in another flavor. What is more often is that some options are missing. Again, this is just my experience. – Arkadiusz Drabczyk Jan 23 '15 at 14:16
  • @l0b0: I didn't write this code, I wouldn't use bash in the first place – Arkadiusz Drabczyk Jan 23 '15 at 14:17
0

Alternatively, if your grep is the GNU grep, you can use it as follows:

man wget | grep -EA3 '^ *-b'

In which -A (a GNU extension) is for print number of lines after matching lines (here 3). you can use appropriate number for complete description.

Example:

$ man wget | grep -EA3 '^ *-b'
       -b
       --background
           Go to background immediately after startup.  If no output file is specified via the -o, output is
           redirected to wget-log.

$ man grep | grep -EA3 '^ *-A'
       -A NUM, --after-context=NUM
              Print NUM lines of trailing context after matching lines.  Places a line containing a  group  separator
              (--)  between  contiguous groups of matches.  With the -o or --only-matching option, this has no effect
              and a warning is given.
0

For a command line experience, use @Costas version.

For a light weight version, man uses the same text interface as less. This means you can use the same commands as less.

# open manual to wget
man wget

# search for -b
/-b

# use "n" to navigate to next version of -b until you find what you want
New contributor
K3ARN3Y is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.