?? ch25_05.htm
字號:
<HTML><!--Distributed by F --><HEAD><TITLE>[Chapter 25] 25.5 Page Through Compressed, RCS, Unprintable Files </TITLE><METANAME="DC.title"CONTENT="UNIX Power Tools"><METANAME="DC.creator"CONTENT="Jerry Peek, Tim O'Reilly & Mike Loukides"><METANAME="DC.publisher"CONTENT="O'Reilly & Associates, Inc."><METANAME="DC.date"CONTENT="1998-08-04T21:43:09Z"><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_04.htm"TITLE='25.4 The "less" Pager: More than "more"'><LINKREL="next"HREF="ch25_06.htm"TITLE="25.6 What's in That White Space? "></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_04.htm"TITLE='25.4 The "less" Pager: More than "more"'><IMGSRC="gifs/txtpreva.gif"SRC="gifs/txtpreva.gif"ALT='Previous: 25.4 The "less" Pager: More than "more"'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_06.htm"TITLE="25.6 What's in That White Space? "><IMGSRC="gifs/txtnexta.gif"SRC="gifs/txtnexta.gif"ALT="Next: 25.6 What's in That White Space? "BORDER="0"></A></TD></TR></TABLE> <HRALIGN="LEFT"WIDTH="515"TITLE="footer"></DIV><DIVCLASS="SECT1"><H2CLASS="sect1"><ACLASS="title"NAME="UPT-ART-7170">25.5 Page Through Compressed, RCS, Unprintable Files </A></H2><TABLECLASS="para.programreference"BORDER="1"><TR><THVALIGN="TOP"><ACLASS="programreference"HREF="examples/index.htm"TITLE="zmore">zmore</A><BR></TH><TDVALIGN="TOP"><ACLASS="indexterm"NAME="AUTOID-27381"></A><ACLASS="indexterm"NAME="AUTOID-27384"></A><ACLASS="indexterm"NAME="AUTOID-27386"></A><ACLASS="indexterm"NAME="AUTOID-27389"></A><SPANCLASS="link">Compressed (<ACLASS="linkend"HREF="ch24_07.htm"TITLE="Compressing Files to Save Space ">24.7</A>)</SPAN>files save disk space.But compressed files aren't as convenient to work with: you have touncompress them before you can read or edit them.<ACLASS="indexterm"NAME="AUTOID-27392"></A>The <EMCLASS="emphasis">zmore</EM> script (also named <EMCLASS="emphasis">zpg</EM> and <EMCLASS="emphasis">zless</EM>)makes the job easier.It uncompresses one or more files and feeds them to a pager:<SPANCLASS="link"><EMCLASS="emphasis">more</EM> (<ACLASS="linkend"HREF="ch25_03.htm"TITLE="Using more to Page Through Files ">25.3</A>)</SPAN>,<EMCLASS="emphasis">pg</EM>, or<SPANCLASS="link"><EMCLASS="emphasis">less</EM> (<ACLASS="linkend"HREF="ch25_04.htm"TITLE='The "less" Pager: More than "more"'>25.4</A>)</SPAN>.(The script uses GNU <EMCLASS="emphasis">gzcat</EM>, which can read both<EMCLASS="emphasis">gzip</EM> and <EMCLASS="emphasis">compress</EM> format.)<ACLASS="indexterm"NAME="AUTOID-27406"></A>The script can also page through files that have been made printable by<SPANCLASS="link"><EMCLASS="emphasis">cat -v -t -e</EM> (<ACLASS="linkend"HREF="ch25_07.htm"TITLE="Show Non-Printing Characters with cat -v or od -c ">25.7</A>, <ACLASS="linkend"HREF="ch25_06.htm"TITLE="What's in That White Space? ">25.6</A>)</SPAN>.This is a safe way to page through files that might have unprintablecharacters that could mess up your terminal if they weren't filtered.Finally, the script can page through the latest revision of an<SPANCLASS="link">RCS file (<ACLASS="linkend"HREF="ch20_14.htm"TITLE="RCS Basics ">20.14</A>)</SPAN>.</TD></TR></TABLE><PCLASS="para">Here's an example.Let's page through the <EMCLASS="emphasis">gzip</EM>ped files <EMCLASS="emphasis">data.gz</EM> and<EMCLASS="emphasis">../summary.gz</EM>.Then we'll read the suspiciously named file <EMCLASS="emphasis">Ex034912</EM> to see what's in it:</P><PCLASS="para"><BLOCKQUOTECLASS="screen"><PRECLASS="screen">% <CODECLASS="userinput"><B>zmore data ../summary</B></CODE> <EMCLASS="emphasis">You don't need to type the .gz</EM> ...<EMCLASS="emphasis">First screen of data.gz, uncompressed</EM>...--More-- ...<EMCLASS="emphasis">The rest of data.gz, uncompressed</EM>...zmore: Press RETURN to see next file, '../summary': ...<EMCLASS="emphasis">First screen of ../summary.gz, uncompressed</EM>...% <CODECLASS="userinput"><B>vmore Ex034912</B></CODE> ...<EMCLASS="emphasis">First screen of Ex034912, filtered with cat -t -v -e</EM>...</PRE></BLOCKQUOTE></P><PCLASS="para">The same script file does all those things.It's written to have eight other<SPANCLASS="link">links (<ACLASS="linkend"HREF="ch18_03.htm"TITLE="Files with Two or More Names">18.3</A>)</SPAN>:<EMCLASS="emphasis">zpg</EM>, <EMCLASS="emphasis">zless</EM>, <EMCLASS="emphasis">vmore</EM>, <EMCLASS="emphasis">vpg</EM>, <EMCLASS="emphasis">vless</EM>,<EMCLASS="emphasis">rcsmore</EM>, <EMCLASS="emphasis">rcspg</EM>, and <EMCLASS="emphasis">rcsless</EM>.The script tests the name it was called with, from <CODECLASS="literal">$0</CODE>, to decidewhether to use <EMCLASS="emphasis">gzcat</EM>, <EMCLASS="emphasis">cat -t -v -e</EM>, or<EMCLASS="emphasis">co -p</EM>, and which pager to run.This trick saves disk space.You can change the pagers used by modifying the script and adding orremoving links to it.The absolute pathnames at the start of the script may need to be changedfor your system.</P><PCLASS="para">Most pager programs can't back up or move around as easily when they'rereading from a pipe.(<EMCLASS="emphasis">less</EM> can.)You can use a temporary file instead.That's not as efficient as using a pipe, but it's good to be able to do.To dothat, add the following two lines after the second <EMCLASS="emphasis">case</EM>statement:</P><PCLASS="para"><TABLECLASS="screen.co"BORDER="1"><TR><THVALIGN="TOP"><PRECLASS="calloutlist"><ACLASS="co"HREF="ch21_03.htm"TITLE="21.3 Unique Names for Temporary Files ">/tmp..$$</A> <ACLASS="co"HREF="ch44_12.htm"TITLE="44.12 Trapping Exits Caused by Interrupts ">trap</A> </PRE></TH><TDVALIGN="TOP"><PRECLASS="screen">temp=/tmp/$myname$$trap 'rm -f $temp; exit' 0 1 2 15</PRE></TD></TR></TABLE></P><PCLASS="para">And change this line inside the <EMCLASS="emphasis">while</EM> loop, around line 38:</P><PCLASS="para"><BLOCKQUOTECLASS="screen"><PRECLASS="screen">*) $cat "$1" | $prog $opts ;;</PRE></BLOCKQUOTE></P><PCLASS="para"> to these three lines:</P><PCLASS="para"><BLOCKQUOTECLASS="screen"><PRECLASS="screen">*) $cat "$1" > $temp $prog $opts $temp ;;</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="ch25_04.htm"TITLE='25.4 The "less" Pager: More than "more"'><IMGSRC="gifs/txtpreva.gif"SRC="gifs/txtpreva.gif"ALT='Previous: 25.4 The "less" Pager: More than "more"'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_06.htm"TITLE="25.6 What's in That White Space? "><IMGSRC="gifs/txtnexta.gif"SRC="gifs/txtnexta.gif"ALT="Next: 25.6 What's in That White Space? "BORDER="0"></A></TD></TR><TR><TDALIGN="LEFT"VALIGN="TOP"WIDTH="172">25.4 The "less" Pager: More than "more"</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.6 What's in That White Space? </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 & 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>
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -