⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ch50_06.htm

📁 the unix power tools
💻 HTM
字号:
<HTML><!--Distributed by F --><HEAD><TITLE>[Chapter 50] 50.6 Searching Online Manual Pages </TITLE><METANAME="DC.title"CONTENT="UNIX Power Tools"><METANAME="DC.creator"CONTENT="Jerry Peek, Tim O'Reilly &amp; Mike Loukides"><METANAME="DC.publisher"CONTENT="O'Reilly &amp; Associates, Inc."><METANAME="DC.date"CONTENT="1998-08-04T21:56:55Z"><METANAME="DC.type"CONTENT="Text.Monograph"><METANAME="DC.format"CONTENT="text/html"SCHEME="MIME"><METANAME="DC.source"CONTENT="1-56592-260-3"SCHEME="ISBN"><METANAME="DC.language"CONTENT="en-US"><METANAME="generator"CONTENT="Jade 1.1/O'Reilly DocBook 3.0 to HTML 4.0"><LINKREV="made"HREF="mailto:online-books@oreilly.com"TITLE="Online Books Comments"><LINKREL="up"HREF="ch50_01.htm"TITLE="50. Help--Online Documentation, etc."><LINKREL="prev"HREF="ch50_05.htm"TITLE="50.5 whereis: Finding Where a Command Is Located "><LINKREL="next"HREF="ch50_07.htm"TITLE="50.7 How UNIX Systems Remember Their Name "></HEAD><BODYBGCOLOR="#FFFFFF"TEXT="#000000"><DIVCLASS="htmlnav"><H1><IMGSRC="gifs/smbanner.gif"ALT="UNIX Power Tools"USEMAP="#srchmap"BORDER="0"></H1><MAPNAME="srchmap"><AREASHAPE="RECT"COORDS="0,0,466,58"HREF="index.htm"ALT="UNIX Power Tools"><AREASHAPE="RECT"COORDS="467,0,514,18"HREF="jobjects/fsearch.htm"ALT="Search this book"></MAP><TABLEWIDTH="515"BORDER="0"CELLSPACING="0"CELLPADDING="0"><TR><TDALIGN="LEFT"VALIGN="TOP"WIDTH="172"><ACLASS="SECT1"HREF="ch50_05.htm"TITLE="50.5 whereis: Finding Where a Command Is Located "><IMGSRC="gifs/txtpreva.gif"SRC="gifs/txtpreva.gif"ALT="Previous: 50.5 whereis: Finding Where a Command Is Located "BORDER="0"></A></TD><TDALIGN="CENTER"VALIGN="TOP"WIDTH="171"><B><FONTFACE="ARIEL,HELVETICA,HELV,SANSERIF"SIZE="-1">Chapter 50<BR>Help--Online Documentation, etc.</FONT></B></TD><TDALIGN="RIGHT"VALIGN="TOP"WIDTH="172"><ACLASS="SECT1"HREF="ch50_07.htm"TITLE="50.7 How UNIX Systems Remember Their Name "><IMGSRC="gifs/txtnexta.gif"SRC="gifs/txtnexta.gif"ALT="Next: 50.7 How UNIX Systems Remember Their Name "BORDER="0"></A></TD></TR></TABLE>&nbsp;<HRALIGN="LEFT"WIDTH="515"TITLE="footer"></DIV><DIVCLASS="SECT1"><H2CLASS="sect1"><ACLASS="title"NAME="UPT-ART-9909">50.6 Searching Online Manual Pages </A></H2><PCLASS="para"><ACLASS="indexterm"NAME="AUTOID-59242"></A><ACLASS="indexterm"NAME="AUTOID-59245"></A>When the other techniques in this chapter don't find the informationyou want, you can try searching the<SPANCLASS="link">online manual page (<ACLASS="linkend"HREF="ch50_01.htm#UPT-ART-4910"TITLE="UNIX Online Documentation ">50.1</A>)</SPAN>files.You'll probably have to wade through a lot of stuff that you don't wantto see, but this method can work when nothing else does.As an example, you remember that there's some command for choppingcolumns out of a file.You try<SPANCLASS="link"><EMCLASS="emphasis">apropos</EM> (<ACLASS="linkend"HREF="ch50_02.htm"TITLE="The apropos Command ">50.2</A>)</SPAN>,but it only mentions <EMCLASS="emphasis">colrm</EM> and <EMCLASS="emphasis">pr</EM>, and those aren't what youwant.You'll usually be able to narrow your search to one or two<SPANCLASS="link">manual page sections (<ACLASS="linkend"HREF="ch50_01.htm#UPT-ART-4910"TITLE="UNIX Online Documentation ">50.1</A>)</SPAN>;here, you know that user commands are in section&nbsp;1.So you go to the manual pages and do a case-insensitive search throughall the files for &quot;column&quot; or &quot;chop&quot;:</P><PCLASS="para"><BLOCKQUOTECLASS="screen"><PRECLASS="screen"><ACLASS="indexterm"NAME="AUTOID-59256"></A><ACLASS="indexterm"NAME="AUTOID-59259"></A>% <CODECLASS="userinput"><B>cd /usr/man/man1</B></CODE>% <CODECLASS="userinput"><B>egrep -i 'column|chop' *</B></CODE>awk.1:Add up first column, print sum and average:colrm.1:colrm \- remove characters from specified columns within each line  ...cut.1:.IX  cut  &quot;&quot;  &quot;\fIcut\fP \(em remove columns from file&quot;  ...</PRE></BLOCKQUOTE></P><PCLASS="para">It's <EMCLASS="emphasis">cut</EM>!Notice that <EMCLASS="emphasis">awk</EM> also handles columns, but <EMCLASS="emphasis">apropos</EM> doesn'tsay so.</P><PCLASS="para">(I cheated on that example: there were other ways to find <EMCLASS="emphasis">cut</EM>-usingthe synonym <EMCLASS="emphasis">apropos field</EM> instead of <EMCLASS="emphasis">apropos column</EM>, for instance.But this method does work in tougher cases.)To search the manual page files, you'll need to know where they'restored.There are lots of possibilities, but the directories<EMCLASS="emphasis">/usr/man</EM> or <EMCLASS="emphasis">/usr/share/man</EM> are good places to look.If the command is local, try <EMCLASS="emphasis">/usr/local/man</EM> and maybe <EMCLASS="emphasis">/opt</EM> (a bigtree where<SPANCLASS="link"><EMCLASS="emphasis">find</EM> (<ACLASS="linkend"HREF="ch17_04.htm"TITLE="Looking for Files with Particular Names ">17.4</A>)</SPAN>can help).If your system has<SPANCLASS="link">fast <EMCLASS="emphasis">find</EM> or <EMCLASS="emphasis">locate</EM> (<ACLASS="linkend"HREF="ch17_18.htm"TITLE='Using "Fast find&quot;'>17.18</A>)</SPAN>,try searching for <CODECLASS="literal">man</CODE> or <CODECLASS="literal">*/man*</CODE>.</P><PCLASS="para">You'll probably find subdirectories with names like <EMCLASS="emphasis">man1</EM>, <EMCLASS="emphasis">man2</EM>,... and/or <EMCLASS="emphasis">cat1</EM>, <EMCLASS="emphasis">cat2</EM>, ....Directory names like <EMCLASS="emphasis">manN</EM> will have unformatted source files for section <EMCLASS="emphasis">N</EM>; the <EMCLASS="emphasis">catN</EM> directories have formatted source files.Or you may just find files named <EMCLASS="emphasis">command.N</EM>, where <EMCLASS="emphasis">N</EM> is <EMCLASS="emphasis">1</EM>for section 1, <EMCLASS="emphasis">2</EM> for section 2, and so on.</P><PCLASS="para"><ACLASS="indexterm"NAME="AUTOID-59296"></A><ACLASS="indexterm"NAME="AUTOID-59299"></A>There are two types of manpage files: unformatted (shown in article<ACLASS="xref"HREF="ch50_11.htm"TITLE="Writing a Simple Man Page with the -man Macros ">50.11</A>)and formatted (with overstriking, as in article<ACLASS="xref"HREF="ch43_18.htm"TITLE="How nroff Makes Bold and Underline; How to Remove It">43.18</A>).The unformatted pages are easier to search because none of the wordswill have embedded backspace characters.The example above shows how.The unformatted pages have<SPANCLASS="link"><EMCLASS="emphasis">nroff</EM> (<ACLASS="linkend"HREF="ch43_13.htm"TITLE="The Text Formatters nroff, troff, ditroff, ... ">43.13</A>)</SPAN>commands and macros in them, though, which can make searching and readingtougher.</P><PCLASS="para">To search formatted pages, you'll want to strip the embedded backspacecharacters.Otherwise, <EMCLASS="emphasis">grep</EM> might miss the word you want because it wasboldfaced or underlined&nbsp;- with backspaces in it.In the example below, a<SPANCLASS="link">shell loop (<ACLASS="linkend"HREF="ch09_11.htm"TITLE="Repeating a Command with a foreach Loop ">9.11</A>, <ACLASS="linkend"HREF="ch09_12.htm"TITLE="The Bourne Shell for Loop ">9.12</A>)</SPAN>applies a series of commands to each file.First,<SPANCLASS="link"><EMCLASS="emphasis">col&nbsp;-b</EM> (<ACLASS="linkend"HREF="ch43_18.htm"TITLE="How nroff Makes Bold and Underline; How to Remove It">43.18</A>)</SPAN>removes the overstriking.<EMCLASS="emphasis">grep</EM> does a search (case-insensitive, as before).Because <EMCLASS="emphasis">grep</EM> is reading its standard input, it doesn't knowthe filename, so a little <EMCLASS="emphasis">sed</EM> command adds the name to thestart of every line <EMCLASS="emphasis">grep</EM> outputs.</P><PCLASS="para"><TABLECLASS="screen.co"BORDER="1"><TR><THVALIGN="TOP"><PRECLASS="calloutlist">&#13;<ACLASS="co"HREF="ch01_16.htm"TITLE="1.16 Wildcards ">*</A> &#13;</PRE></TH><TDVALIGN="TOP"><PRECLASS="screen">$ <CODECLASS="userinput"><B>cd /usr/man/cat1</B></CODE><ACLASS="indexterm"NAME="AUTOID-59319"></A>$ <CODECLASS="userinput"><B>for file in *</B></CODE>&gt; <CODECLASS="userinput"><B>do col -b &lt; $file | grep -i column | sed &quot;s/^/${file}:/&quot;</B></CODE>&gt; <CODECLASS="userinput"><B>done</B></CODE>awk.1:   Add up first column, print   sum and average:   ...cut.1:   Use cut to cut out columns from a table or fields from each   ...</PRE></TD></TR></TABLE></P><PCLASS="para">In Bourne shells, you can pipe the output of that loop to a pager (like<SPANCLASS="link"><EMCLASS="emphasis">less</EM> (<ACLASS="linkend"HREF="ch25_04.htm"TITLE='The "less&quot; Pager: More than "more&quot;'>25.4</A>)</SPAN>)to see the output a screenful at a time and quit (with <CODECLASS="literal">q</CODE>) whenyou're done.Change the last line of the <EMCLASS="emphasis">for</EM> loop to:</P><PCLASS="para"><BLOCKQUOTECLASS="screen"><PRECLASS="screen">done | less</PRE></BLOCKQUOTE></P><DIVCLASS="sect1info"><PCLASS="SECT1INFO">- <SPANCLASS="authorinitials">JP</SPAN></P></DIV></DIV><DIVCLASS="htmlnav"><P></P><HRALIGN="LEFT"WIDTH="515"TITLE="footer"><TABLEWIDTH="515"BORDER="0"CELLSPACING="0"CELLPADDING="0"><TR><TDALIGN="LEFT"VALIGN="TOP"WIDTH="172"><ACLASS="SECT1"HREF="ch50_05.htm"TITLE="50.5 whereis: Finding Where a Command Is Located "><IMGSRC="gifs/txtpreva.gif"SRC="gifs/txtpreva.gif"ALT="Previous: 50.5 whereis: Finding Where a Command Is Located "BORDER="0"></A></TD><TDALIGN="CENTER"VALIGN="TOP"WIDTH="171"><ACLASS="book"HREF="index.htm"TITLE="UNIX Power Tools"><IMGSRC="gifs/txthome.gif"SRC="gifs/txthome.gif"ALT="UNIX Power Tools"BORDER="0"></A></TD><TDALIGN="RIGHT"VALIGN="TOP"WIDTH="172"><ACLASS="SECT1"HREF="ch50_07.htm"TITLE="50.7 How UNIX Systems Remember Their Name "><IMGSRC="gifs/txtnexta.gif"SRC="gifs/txtnexta.gif"ALT="Next: 50.7 How UNIX Systems Remember Their Name "BORDER="0"></A></TD></TR><TR><TDALIGN="LEFT"VALIGN="TOP"WIDTH="172">50.5 whereis: Finding Where a Command Is Located </TD><TDALIGN="CENTER"VALIGN="TOP"WIDTH="171"><ACLASS="index"HREF="index/idx_0.htm"TITLE="Book Index"><IMGSRC="gifs/index.gif"SRC="gifs/index.gif"ALT="Book Index"BORDER="0"></A></TD><TDALIGN="RIGHT"VALIGN="TOP"WIDTH="172">50.7 How UNIX Systems Remember Their Name </TD></TR></TABLE><HRALIGN="LEFT"WIDTH="515"TITLE="footer"><IMGSRC="gifs/smnavbar.gif"SRC="gifs/smnavbar.gif"USEMAP="#map"BORDER="0"ALT="The UNIX CD Bookshelf Navigation"><MAPNAME="map"><AREASHAPE="RECT"COORDS="0,0,73,21"HREF="../index.htm"ALT="The UNIX CD Bookshelf"><AREASHAPE="RECT"COORDS="74,0,163,21"HREF="index.htm"ALT="UNIX Power Tools"><AREASHAPE="RECT"COORDS="164,0,257,21"HREF="../unixnut/index.htm"ALT="UNIX in a Nutshell"><AREASHAPE="RECT"COORDS="258,0,321,21"HREF="../vi/index.htm"ALT="Learning the vi Editor"><AREASHAPE="RECT"COORDS="322,0,378,21"HREF="../sedawk/index.htm"ALT="sed &amp; awk"><AREASHAPE="RECT"COORDS="379,0,438,21"HREF="../ksh/index.htm"ALT="Learning the Korn Shell"><AREASHAPE="RECT"COORDS="439,0,514,21"HREF="../lrnunix/index.htm"ALT="Learning the UNIX Operating System"></MAP></DIV></BODY></HTML>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -