매뉴얼 페이지의 전체 텍스트 검색 및 apropos(1)와 같은 콘솔에서 이름 및 설명 목록 가져오기

매뉴얼 페이지의 전체 텍스트 검색 및 apropos(1)와 같은 콘솔에서 이름 및 설명 목록 가져오기

マニュアルページで全文検索を実行し、そのようなコンソールから関連マニュアルページの名前と説明のリストを取得する方法はありますかapropos(1)

マニュアルページの内容の全文検索を使用できますman -K。しかし、3つの問題があります。

  1. man -K最初の結果のタイトルはコンソールに表示されません。

  2. man -K以下のようにマンページのタイトルのみが表示されます。

    --Man-- next: ansible(1) [ view (return) | skip (Ctrl-D) | quit (Ctrl-C) ]

  3. man -KCtrl-D맨페이지 내용 보기를 건너뛰어야 합니다 . 따라서 yes(1)응답을 에 전달하는 데 사용할 수 없습니다 man -K.

ベストアンサー1

더 쉬운 방법이 있을 수 있지만 검색어가 포함된 파일의 경로를 인쇄하는 man -K것과 결합할 수 있다는 것을 알았습니다. 예를 들어 Whatis 정보를 추출하는 것과 결합할 수 있습니다.-wlexgrog

$ man -Kws1 apropos | sort -u | xargs -rd '\n' lexgrog | perl -pe's/.*?: "(.*)"/$1/'
apropos - search the manual page names and descriptions
emacs - GNU project Emacs editor
groffer - display groff files and man pages on X and tty
info - read Info documents
lexgrog - parse header information in man pages
man - an interface to the system reference manuals
manpath - determine search path for manual pages
scanimage - scan an image
whatis - display one-line manual page descriptions
xman - Manual page display program for the X Window System

(이것은 GNU가 그것 과 옵션을 xargs대표한다고 가정하지만 , 후자가 필요하지는 않을 것입니다)-r-d

full-apropos다음 과 같은 스크립트나 함수 로 변환할 수 있습니다 .

#! /bin/sh -
man -Kw "$@" |
  sort -u |
  xargs -rd '\n' lexgrog |
  perl -pe's/.*?: "(.*)"/$1/'

그러나 우리는 정보의 man 부분을 놓치고 있습니다. 파일 경로에 있으므로 다음을 사용하여 다시 추가할 수 있습니다.

#! /bin/sh -
man -Kw "$@" |
  sort -u |
  while IFS= read -r file; do
    section=${file%/*}
    section=${section##*/man}
    lexgrog -- "$file" |
      perl -spe's/.*?: "(.*)"/$1/; s/ - / ($s)$&/' -- "-s=$section"
  done

おすすめ記事