Any way to cat few lines of man page to show on stdout for reference

manstdout

This is a simple question. Trying my best to put it in simple word. Hope you get it without much confusion –

I read a man page for some command-switch/option which has a long description. I read it, press q to escape and try the option. But then I do need to go back to same man page section for some more info. So, I repeat the steps

I would like to know if there is any way to output the contents of man page onto the stdout for referring it quickly.

For example let's take short-one cal, may be something like

cat `man cal`

would be effective and help achieve the desired requirement.

Any hints?

Best Answer

You could run the output of man into the col command and then pipe this to less. Once in less you can drop to a shell while still maintaining your location in less.

$ man col | col -b | less

Once in less you can use !bash to get to a prompt to do what you want. When you're done you type exit to return back to your location in less.

Example

Here's a demo showing the whole operation.

            ss of demo

Tell man to use a different pager

You can also tell man to use different pagers via the -P switch. So we could streamline the above method like so:

$ man -P less col

This is invoking man and then outputting the contents of the page to less, where again we can use !bash to get to a shell. To return we use the same steps as above, exit.

What's wrong with the default pager?

Actually nothing.

$ man col

It too can take the command !bash to escape to a shell, where again we can type exit to get back to the location where we were previously within the man page.

What else?

If you're feeling really crazy you can use vim as an alternative pager too. Setting this up is a bit of a task but it's doable, directions for doing so are here in the vim wikia topic titled: Using vim as a man-page viewer under Unix.

Don't let the above page fool you, it doesn't just cover vim methods. That topic covers dozens of ways you can change your man page pager in addition to using vim.

Related Question