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

📄 ch25_15.htm

📁 the unix power tools
💻 HTM
字号:
<HTML><!--Distributed by F --><HEAD><TITLE>[Chapter 25] 25.15 Finer Control on tail </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:28Z"><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_14.htm"TITLE="25.14 How to Look at the End of a File: tail "><LINKREL="next"HREF="ch25_16.htm"TITLE="25.16 How to Look at a File as It Grows "></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_14.htm"TITLE="25.14 How to Look at the End of a File: tail "><IMGSRC="gifs/txtpreva.gif"SRC="gifs/txtpreva.gif"ALT="Previous: 25.14 How to Look at the End of a File: tail "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_16.htm"TITLE="25.16 How to Look at a File as It Grows "><IMGSRC="gifs/txtnexta.gif"SRC="gifs/txtnexta.gif"ALT="Next: 25.16 How to Look at a File as It Grows "BORDER="0"></A></TD></TR></TABLE>&nbsp;<HRALIGN="LEFT"WIDTH="515"TITLE="footer"></DIV><DIVCLASS="SECT1"><H2CLASS="sect1"><ACLASS="title"NAME="UPT-ART-7946">25.15 Finer Control on tail </A></H2><PCLASS="para"><ACLASS="indexterm"NAME="AUTOID-28000"></A><ACLASS="indexterm"NAME="AUTOID-28003"></A>What if you need to look at the last 11 lines of the file? Thecommand <CODECLASS="literal">tail&nbsp;-</CODE><CODECLASS="replaceable"><I>n</I></CODE> shows the final <CODECLASS="replaceable"><I>n</I></CODE>&nbsp;lines. Thecommand <CODECLASS="literal">tail&nbsp;+</CODE><CODECLASS="replaceable"><I>n</I></CODE> discards the first <CODECLASS="replaceable"><I>n</I></CODE>-1&nbsp;lines, giving you line <CODECLASS="replaceable"><I>n</I></CODE> and everything that follows it.</P><PCLASS="para">You can also tell <EMCLASS="emphasis">tail</EM> to count the number of characters or thenumber of 512-byte blocks. To do so, use the <EMCLASS="emphasis">-c</EM> option (countcharacters) or the <EMCLASS="emphasis">-b</EM> option (count blocks). If you want tostate explicitly that you're interested in lines, give the <EMCLASS="emphasis">-l</EM>option.</P><BLOCKQUOTECLASS="note"><PCLASS="para"><STRONG>NOTE:</STRONG> <EMCLASS="emphasis">tail</EM> is one of the UNIX programs that likes its arguments to besmashed together. In other words, if you want to look at the lastthree blocks of a file, give the command <EMCLASS="emphasis">tail -3b</EM>. If you givethe command <EMCLASS="emphasis">tail&nbsp;-3 -b</EM>, <EMCLASS="emphasis">tail</EM> will happily assume that youwant to look at the file <EMCLASS="emphasis">-b</EM>. This also applies to the <EMCLASS="emphasis">-f</EM>option, which we'll discuss a bit in article<ACLASS="xref"HREF="ch25_16.htm"TITLE="How to Look at a File as It Grows ">25.16</A>.For example, the command <EMCLASS="emphasis">tail -4b&nbsp;mail.txt</EM> dumps the last 2048&nbsp;bytes (four blocks, each 512 bytes) of my <EMCLASS="emphasis">mail.txt</EM> file to thescreen. </P></BLOCKQUOTE><PCLASS="para"><ACLASS="indexterm"NAME="AUTOID-28030"></A>Many versions of <EMCLASS="emphasis">tail</EM> also have a <EMCLASS="emphasis">-r</EM> option that shows the filein reverse order, starting from the last line.(Also see article<ACLASS="xref"HREF="ch25_19.htm"TITLE="Reverse Lines in Long Files with flip ">25.19</A>.)</P><PCLASS="para">Some versions of UNIX may limit the maximum number of lines that<EMCLASS="emphasis">tail</EM>, especially <EMCLASS="emphasis">tail -r</EM>, can display.</P><DIVCLASS="sect1info"><PCLASS="SECT1INFO">- <SPANCLASS="authorinitials">ML</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_14.htm"TITLE="25.14 How to Look at the End of a File: tail "><IMGSRC="gifs/txtpreva.gif"SRC="gifs/txtpreva.gif"ALT="Previous: 25.14 How to Look at the End of a File: tail "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_16.htm"TITLE="25.16 How to Look at a File as It Grows "><IMGSRC="gifs/txtnexta.gif"SRC="gifs/txtnexta.gif"ALT="Next: 25.16 How to Look at a File as It Grows "BORDER="0"></A></TD></TR><TR><TDALIGN="LEFT"VALIGN="TOP"WIDTH="172">25.14 How to Look at the End of a File: tail </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.16 How to Look at a File as It Grows </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 + -