Linux 매뉴얼 페이지에서 일부 플래그를 쿼리합니다.

Linux 매뉴얼 페이지에서 일부 플래그를 쿼리합니다.

나는 종종 man iptables체크 -t플래그와 같은 특정 플래그를 확인하기 위해 CLI 도구의 매뉴얼 페이지를 엽니다.

이를 단순화하는 도구가 있습니까? 맨페이지의 내용을 파악하기 위해 Bash에서 간단한 함수를 작성할 수도 있지만, 내가 원하는 것(예: 특정 플래그에 대한 설명)을 정확히 찾기 위해 맨페이지 구조를 사용하는 무언가를 찾고 있습니다.

답변1

매뉴얼 페이지 프로그램이 그렇다고 가정하면 less환경 변수를 사용하여 모든 명령을 앞에 추가할 수 있습니다.lessLESS

따라서 다음 -t옵션을 검색하십시오 man iptables.

LESS='+/-t' man iptables

/-t이는 내에서 실행하는 것과 동일한 효과를 갖습니다 man ipatbles. 더 미세한 제어를 위해 모드를 변경할 수 있습니다.

필요한 경우 더 쉽게 액세스할 수 있는 기능을 만들 수 있습니다.

search_man () { LESS=+/"$2" man "$1" ;}

현재 하고 있는 일:

search_man iptables '-t'              

같은 효과가 있을 것입니다.


편집하다:

검색하는 대신 매뉴얼 페이지의 특정 옵션으로 이동하려면 정규식 일치를 사용할 수 있습니다 LESS.

LESS='+/^[[:blank:]]+-t' man iptables

-t그러면 옵션 설명으로 바로 이동됩니다 man iptables. 유사하게 함수를 정의할 수도 있습니다.

search_man () { LESS=+/^[[:blank:]]+"$2" man "$1" ;}

답변2

특정 플래그에 대한 매뉴얼 페이지를 쿼리하기 위한 API/메커니즘을 찾지 못했습니다. 하지만,이 간단한 기능정확히 내가 필요한 것 같습니다.

function manswitch () { man $1 | less -p "^ +$2" }

용법:

manswitch iptables -t

답변3

한 가지. 지금. 이 기능:

flag() {
    man "$1" | grep -- "$2";
}

작동 방식은 다음과 같습니다.

$ flag iptables -t
iptables [-t table] {-A|-C|-D} chain rule-specification
ip6tables [-t table] {-A|-C|-D} chain rule-specification
iptables [-t table] -I chain [rulenum] rule-specification
iptables [-t table] -R chain rulenum rule-specification
iptables [-t table] -D chain rulenum
iptables [-t table] -S [chain [rulenum]]
iptables [-t table] {-F|-L|-Z} [chain [rulenum]] [options...]
iptables [-t table] -N chain
iptables [-t table] -X [chain]
iptables [-t table] -P chain target
iptables [-t table] -E old-chain-name new-chain-name
target = -j targetname [per-target-options]
-t, --table table
           This  is  the  default table (if no -t option is passed). It
        iptables -t nat -n -L

음, 마지막 두 줄이 깨졌습니다.

어쨌든, 그것을 당신의 것에 추가하는 방법을 알고 있습니까 .bashrc? 아니면 당신의 스크립트보다는 스크립트를 선호합니까 ~/bin?

버전 1.1

flag() {
    man "$1" | grep -A5 -- "$2";
}

$ flag iptables -t
       iptables [-t table] {-A|-C|-D} chain rule-specification

       ip6tables [-t table] {-A|-C|-D} chain rule-specification

       iptables [-t table] -I chain [rulenum] rule-specification

       iptables [-t table] -R chain rulenum rule-specification

       iptables [-t table] -D chain rulenum

       iptables [-t table] -S [chain [rulenum]]

       iptables [-t table] {-F|-L|-Z} [chain [rulenum]] [options...]

       iptables [-t table] -N chain

       iptables [-t table] -X [chain]

       iptables [-t table] -P chain target

       iptables [-t table] -E old-chain-name new-chain-name

       rule-specification = [matches...] [target]

       match = -m matchname [per-match-options]

       target = -j targetname [per-target-options]

DESCRIPTION
       Iptables  and ip6tables are used to set up, maintain, and inspect the tables of IPv4 and IPv6 packet filter rules in the Linux kernel.  Several different tables may be defined.  Each table contains a
       number of built-in chains and may also contain user-defined chains.

--
       -t, --table table
              This option specifies the packet matching table which the command should operate on.  If the kernel is configured with automatic module loading, an attempt will be made to load the appropriate
              module for that table if it is not already there.

              The tables are as follows:

--
                  This is the default table (if no -t option is passed). It contains the built-in chains INPUT (for packets destined to local sockets), FORWARD (for packets being routed  through  the  box),
                  and OUTPUT (for locally-generated packets).

              nat:
                  This  table is consulted when a packet that creates a new connection is encountered.  It consists of three built-ins: PREROUTING (for altering packets as soon as they come in), OUTPUT (for
                  altering locally-generated packets before routing), and POSTROUTING (for altering packets as they are about to go out).  IPv6 NAT support is available since kernel 3.7.
--
               iptables -t nat -n -L
              Please note that it is often used with the -n option, in order to avoid long reverse DNS lookups.  It is legal to specify the -Z (zero) option as well, in which case the chain(s) will be atom‐
              ically listed and zeroed.  The exact output is affected by the other arguments given. The exact rules are suppressed until you use
               iptables -L -v

       -S, --list-rules [chain]

관련 정보