32

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?

ironsand
  • 5,205

8 Answers8

23

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.

Costas
  • 14,916
18

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.

fluffy
  • 975
12

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'
Mikel
  • 57,299
  • 15
  • 134
  • 153
6

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.

chaos
  • 48,171
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 "https://explainshell.com/explain/$cmd?args=$args"| tail -n +10

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

$ rman wget -b    
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

I got it from here. Thanks to the author!

Jeff Schaller
  • 67,283
  • 35
  • 116
  • 255
  • 4
    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.
Pandya
  • 24,618
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
0

You need to use col -b or col -bx before using sed:

$ man wget | col -bx | sed -n "/^  *-b/,/^$/p"
       -b
       --background
           Go to background immediately after startup.  If no output file is
           specified via the -o, output is redirected to wget-log.
shin
  • 749