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

📄 ch25_02.htm

📁 the unix power tools
💻 HTM
字号:
<HTML><!--Distributed by F --><HEAD><TITLE>[Chapter 25] 25.2 Four Ways to Skin a cat </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:43:06Z"><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="ch25_01.htm"TITLE="25. Showing What's in a File"><LINKREL="prev"HREF="ch25_01.htm"TITLE="25.1 Cracking the Nut "><LINKREL="next"HREF="ch25_03.htm"TITLE="25.3 Using more to Page Through Files "></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="ch25_01.htm"TITLE="25.1 Cracking the Nut "><IMGSRC="gifs/txtpreva.gif"SRC="gifs/txtpreva.gif"ALT="Previous: 25.1 Cracking the Nut "BORDER="0"></A></TD><TDALIGN="CENTER"VALIGN="TOP"WIDTH="171"><B><FONTFACE="ARIEL,HELVETICA,HELV,SANSERIF"SIZE="-1">Chapter 25<BR>Showing What's in a File</FONT></B></TD><TDALIGN="RIGHT"VALIGN="TOP"WIDTH="172"><ACLASS="SECT1"HREF="ch25_03.htm"TITLE="25.3 Using more to Page Through Files "><IMGSRC="gifs/txtnexta.gif"SRC="gifs/txtnexta.gif"ALT="Next: 25.3 Using more to Page Through Files "BORDER="0"></A></TD></TR></TABLE>&nbsp;<HRALIGN="LEFT"WIDTH="515"TITLE="footer"></DIV><DIVCLASS="SECT1"><H2CLASS="sect1"><ACLASS="title"NAME="UPT-ART-7360">25.2 Four Ways to Skin a cat </A></H2><PCLASS="para"><ACLASS="indexterm"NAME="AUTOID-27146"></A><ACLASS="indexterm"NAME="AUTOID-27148"></A>The <EMCLASS="emphasis">cat</EM> command may well be the first command new usershear about, if only because of its odd name.<EMCLASS="emphasis">cat</EM> stands for con<EMCLASS="emphasis">cat</EM>enate or, as some would say,catenate. Both words mean the same thing: to connectin a series. The <EMCLASS="emphasis">cat</EM> command takes its filename arguments,and strings their contents together. Essentially, <EMCLASS="emphasis">cat</EM> takesits input and spits it out again.</P><PCLASS="para"><EMCLASS="emphasis">cat</EM> has many uses, but the four most basic applications aredescribed in the following list.In many ways, they don't illustrate <EMCLASS="emphasis">cat</EM> somuch as they illustrate the shell's <SPANCLASS="link">output redirection (<ACLASS="linkend"HREF="ch13_01.htm#UPT-ART-1023"TITLE="Using Standard Input and Output">13.1</A>)</SPAN>mechanism.</P><OLCLASS="orderedlist"><LICLASS="listitem"><PCLASS="para">First form:</P><PCLASS="para"><BLOCKQUOTECLASS="screen"><PRECLASS="screen">% <CODECLASS="userinput"><B>cat</B></CODE> <CODECLASS="replaceable"><I>file</I></CODE>% <CODECLASS="userinput"><B>cat</B></CODE> <CODECLASS="replaceable"><I>file1 file2 file...</I></CODE></PRE></BLOCKQUOTE></P><PCLASS="para">Use this form to display one or more files on the screen.The output doesn't pause when the screen is full. As a result,if your files are more than one screenful long, the outputwill whiz by without giving you a chance to read it.  To readoutput by screenfuls, use the <SPANCLASS="link"><EMCLASS="emphasis">more</EM> (<ACLASS="linkend"HREF="ch25_03.htm"TITLE="Using more to Page Through Files ">25.3</A>)</SPAN>command or some other 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>.[1]</P><BLOCKQUOTECLASS="footnote"><PCLASS="para">[1] You may think this command form is pointless.The truth is, this form is rarely used in such a basic way.More often, you'll use this form along with some of <EMCLASS="emphasis">cat</EM>'s displayoptions or connect this command to other UNIX commands via a <SPANCLASS="link">pipe (<ACLASS="linkend"HREF="ch01_03.htm"TITLE="Programs Are Designed to Work Together ">1.3</A>)</SPAN>.</P></BLOCKQUOTE></LI><LICLASS="listitem"><PCLASS="para">Second form:</P><PCLASS="para"><BLOCKQUOTECLASS="screen"><PRECLASS="screen">% <CODECLASS="userinput"><B>cat</B></CODE> <CODECLASS="replaceable"><I>files</I></CODE> <CODECLASS="userinput"><B>&gt;</B></CODE> <CODECLASS="replaceable"><I>new_file</I></CODE></PRE></BLOCKQUOTE></P><PCLASS="para">Use this form when you want to combine several smaller files intoone large file. Be sure the destination file does not already exist;otherwise, it will be replaced by the new contents (effectively destroying theoriginal). For example, the command:</P><PCLASS="para"><BLOCKQUOTECLASS="screen"><PRECLASS="screen">% <CODECLASS="userinput"><B>cat chap1 chap2 chap3 &gt; book</B></CODE></PRE></BLOCKQUOTE></P><PCLASS="para">creates a new file, <EMCLASS="emphasis">book</EM>, composed of three files,one after the other. The three component files still exist as <EMCLASS="emphasis">chap1</EM>, <EMCLASS="emphasis">chap2</EM>, and <EMCLASS="emphasis">chap3</EM>.</P></LI><LICLASS="listitem"><PCLASS="para">Third form:</P><PCLASS="para"><BLOCKQUOTECLASS="screen"><PRECLASS="screen">% <CODECLASS="userinput"><B>cat</B></CODE> <CODECLASS="replaceable"><I>file</I></CODE> <CODECLASS="userinput"><B>&gt;&gt;</B></CODE> <CODECLASS="replaceable"><I>existing_file</I></CODE>% <CODECLASS="userinput"><B>cat</B></CODE> <CODECLASS="replaceable"><I>files</I></CODE> <CODECLASS="userinput"><B>&gt;&gt;</B></CODE> <CODECLASS="replaceable"><I>existing_file</I></CODE></PRE></BLOCKQUOTE></P><PCLASS="para"><ACLASS="indexterm"NAME="AUTOID-27209"></A>Use this form to add one or more files to the end of an existingfile. For example:</P><PCLASS="para"><BLOCKQUOTECLASS="screen"><PRECLASS="screen">% <CODECLASS="userinput"><B>cat note1 note2 &gt; note_list</B></CODE>% <CODECLASS="userinput"><B>cat note3 &gt;&gt; note_list</B></CODE></PRE></BLOCKQUOTE></P><PCLASS="para"></P></LI><LICLASS="listitem"><PCLASS="para"><ACLASS="indexterm"NAME="AUTOID-27219"></A>Fourth form:</P><PCLASS="para"><BLOCKQUOTECLASS="screen"><PRECLASS="screen">% <CODECLASS="userinput"><B>cat &gt;</B></CODE> <CODECLASS="replaceable"><I>newfile</I></CODE></PRE></BLOCKQUOTE></P><PCLASS="para">Use this form as a quick-and-dirty way to create a new file.This is useful when you aren't yet familiar with any of thestandard text editors. With this command, everythingyou type at the keyboard goes into the new file.(You won't be able to back up to a previous line.)To finish your input, enter CTRL-d on a line by itself.</P></LI></OL><PCLASS="para">&#13;Well, that was just in case there are some beginners on board.Articles<ACLASS="xref"HREF="ch13_13.htm"TITLE='The "Filename&quot; - '>13.13</A>,<ACLASS="xref"HREF="ch25_07.htm"TITLE="Show Non-Printing Characters with cat -v or od -c ">25.7</A>,<ACLASS="xref"HREF="ch25_10.htm"TITLE="Squash Extra Blank Lines ">25.10</A>,and<ACLASS="xref"HREF="ch25_21.htm"TITLE="Numbering Lines ">25.21</A>give some more useful tips about <EMCLASS="emphasis">cat</EM> options.</P><DIVCLASS="sect1info"><PCLASS="SECT1INFO">- <SPANCLASS="authorinitials">DG</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="ch25_01.htm"TITLE="25.1 Cracking the Nut "><IMGSRC="gifs/txtpreva.gif"SRC="gifs/txtpreva.gif"ALT="Previous: 25.1 Cracking the Nut "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="ch25_03.htm"TITLE="25.3 Using more to Page Through Files "><IMGSRC="gifs/txtnexta.gif"SRC="gifs/txtnexta.gif"ALT="Next: 25.3 Using more to Page Through Files "BORDER="0"></A></TD></TR><TR><TDALIGN="LEFT"VALIGN="TOP"WIDTH="172">25.1 Cracking the Nut </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">25.3 Using more to Page Through Files </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 + -