在 bash 中快速搜索命令选项

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/17509757/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-18 05:50:51  来源:igfitidea点击:

Quick search of command options in bash

bashmanpage

提问by Sergey Ivanov

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 --helpstating help on type option of find.

我发现自己经常在 bash 中寻找命令的参数。例如,find -type f -name '*py' -print0。为了找到所有这些,我需要通过 man、info 或 --help 选项,这既费力又费时。有什么办法可以让这个搜索即时进行。理想情况下,我希望看到类似的内容:find -type --help说明有关查找类型选项的帮助。

回答by Blaz Balon

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

如果您的手册页在其中打开,less您可以使用/它进行搜索。

man find

man find

/-type

/-type

n, for next search

n, 下次搜索

Nfor previous search

N以前的搜索

回答by elcash

Here's something I have in my .bashrc

这是我在 .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 "" | grep -C10 --group-separator="==============================" -- ""
    fi
}

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

mans find type在手册页中搜索所有出现的短语“type”。

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

或者:( mans find -type使用破折号)如果您知道您正在寻找的确切选项。

回答by gmoktop

You can put

你可以放

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

to your .bashrc. Then mangrep pattern pagewill open the manpage with lessand directly search for pattern, as in Blaz Balons answer. So

到您的.bashrc. 然后mangrep pattern page将打开联机帮助页less并直接搜索模式,如Blaz Balons answer 中所示。所以

mangrep " -print" find

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

为您提供了正确的位置-print的选项find。而且您仍然可以n/N用于向前和向后搜索以及 less 的所有其他功能。