30

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?

1
  • wget -h | grep '\-b' Jan 23, 2015 at 14:29

8 Answers 8

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.

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

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.

1
  • @drewbenn Oh, nice. I've always just pressed /+enter to continue on.
    – fluffy
    Jan 25, 2015 at 20:27
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'
4
  • Also your desc script is very helpful.
    – Pandya
    Oct 4, 2014 at 7:07
  • 1
    Just decided to rename it to he, as in short help, plus he/man.
    – Mikel
    Oct 4, 2014 at 7:19
  • Updated to work with the new example, wget -b.
    – Mikel
    Jan 26, 2015 at 7:59
  • I cannot imagine why such simple functionality wasn't implemented natively and one should write a script to achieve that
    – Suncatcher
    Nov 20, 2020 at 20:05
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.

3
  • 1
    {print} can be omitted
    – Costas
    Jan 23, 2015 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, 2015 at 19:10
  • 1
    .*$ can be omitted too Jan 29, 2015 at 22:13
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!

4
  • 4
    It's important to note that this potentially documents a different implementation/version of the commands from those installed on the machine. Jan 23, 2015 at 14:11
  • Also, there's no escaping and bad quoting in the code.
    – l0b0
    Jan 23, 2015 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. Jan 23, 2015 at 14:16
  • @l0b0: I didn't write this code, I wouldn't use bash in the first place Jan 23, 2015 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
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.

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.