Question

I found myself in a situation where I constantly look for parameters of a command in bash. For instance, find -type f -name '*py' -print0. In order to find all of those I need to go through man,info, or --help option which is laborious and time consuming. Is there any way to make this search instant. Ideally, I would love to see something like: find -type --help stating help on type option of find.

Was it helpful?

Solution

If your man pages open in less you can use / to search over it.

man find

/-type

n, for next search

N for previous search

OTHER TIPS

Here's something I have in my .bashrc

# man search
mans()
{
    if [ $# -ne 2 ]; then
        echo "I need 2 args.  a man page and a search phrase."
        exit 1
    else
        man -Pless "$1" | grep -C10 --group-separator="==============================" -- "$2"
    fi
}

mans find type searches the man page for all occurrences of the phrase "type."

Or: mans find -type (with the dash) if you know the exact option you're looking for.

You can put

function mangrep { man -P less\ -p\ \""${1}"\" ${2}; }

to your .bashrc. Then mangrep pattern page will open the manpage with less and directly search for pattern, as in Blaz Balons answer. So

mangrep " -print" find

gives you the right spot for the -print option of find. And you can still use n/N for forward and backward searching as well as all other features of less.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top