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

📄 filearchiv.html

📁 Shall高级编程
💻 HTML
📖 第 1 页 / 共 5 页
字号:
><DL><DT><ANAME="GZIPREF"></A><BCLASS="COMMAND">gzip</B></DT><DD><P>The standard GNU/UNIX compression utility, replacing	      the inferior and proprietary	      <BCLASS="COMMAND">compress</B>. The corresponding decompression	      command is <BCLASS="COMMAND">gunzip</B>, which is the equivalent of	      <BCLASS="COMMAND">gzip -d</B>.</P><DIVCLASS="NOTE"><TABLECLASS="NOTE"WIDTH="90%"BORDER="0"><TR><TDWIDTH="25"ALIGN="CENTER"VALIGN="TOP"><IMGSRC="common/note.png"HSPACE="5"ALT="Note"></TD><TDALIGN="LEFT"VALIGN="TOP"><P>The <TTCLASS="OPTION">-c</TT> option sends the output of	      <BCLASS="COMMAND">gzip</B> to <TTCLASS="FILENAME">stdout</TT>. This	      is useful when <AHREF="special-chars.html#PIPEREF">piping</A> to other	      commands.</P></TD></TR></TABLE></DIV><P><ANAME="ZCATREF"></A></P><P>The <BCLASS="COMMAND">zcat</B> filter decompresses a	      <ICLASS="FIRSTTERM">gzipped</I> file to	      <TTCLASS="FILENAME">stdout</TT>, as possible input to a pipe or	      redirection. This is, in effect, a <BCLASS="COMMAND">cat</B>	      command that works on compressed files (including files	      processed with the older <AHREF="filearchiv.html#COMPRESSREF">compress</A>	      utility). The <BCLASS="COMMAND">zcat</B> command is equivalent to	      <BCLASS="COMMAND">gzip -dc</B>.</P><DIVCLASS="CAUTION"><TABLECLASS="CAUTION"WIDTH="90%"BORDER="0"><TR><TDWIDTH="25"ALIGN="CENTER"VALIGN="TOP"><IMGSRC="common/caution.png"HSPACE="5"ALT="Caution"></TD><TDALIGN="LEFT"VALIGN="TOP"><P>On some commercial UNIX systems, <BCLASS="COMMAND">zcat</B>	      is a synonym for <BCLASS="COMMAND">uncompress -c</B>,	      and will not work on <ICLASS="FIRSTTERM">gzipped</I>	      files.</P></TD></TR></TABLE></DIV><P>See also <AHREF="comparison-ops.html#EX14">Example 7-7</A>.</P></DD><DT><ANAME="BZIPREF"></A><BCLASS="COMMAND">bzip2</B></DT><DD><P>An alternate compression utility, usually more efficient	      (but slower) than <BCLASS="COMMAND">gzip</B>, especially on	      large files. The corresponding decompression command is	      <BCLASS="COMMAND">bunzip2</B>.</P><DIVCLASS="NOTE"><TABLECLASS="NOTE"WIDTH="90%"BORDER="0"><TR><TDWIDTH="25"ALIGN="CENTER"VALIGN="TOP"><IMGSRC="common/note.png"HSPACE="5"ALT="Note"></TD><TDALIGN="LEFT"VALIGN="TOP"><P>Newer versions of <AHREF="filearchiv.html#TARREF">tar</A> have been patched with	      <BCLASS="COMMAND">bzip2</B> support.</P></TD></TR></TABLE></DIV></DD><DT><ANAME="COMPRESSREF"></A><BCLASS="COMMAND">compress</B>, <ANAME="UNCOMPRESSREF"></A><BCLASS="COMMAND">uncompress</B></DT><DD><P>This is an older, proprietary compression	      utility found in commercial UNIX distributions. The	      more efficient <BCLASS="COMMAND">gzip</B> has largely	      replaced it. Linux distributions generally include a	      <BCLASS="COMMAND">compress</B> workalike for compatibility,	      although <BCLASS="COMMAND">gunzip</B> can unarchive files	      treated with <BCLASS="COMMAND">compress</B>.</P><DIVCLASS="TIP"><TABLECLASS="TIP"WIDTH="90%"BORDER="0"><TR><TDWIDTH="25"ALIGN="CENTER"VALIGN="TOP"><IMGSRC="common/tip.png"HSPACE="5"ALT="Tip"></TD><TDALIGN="LEFT"VALIGN="TOP"><P>The <BCLASS="COMMAND">znew</B> command transforms	      <ICLASS="FIRSTTERM">compressed</I> files into	      <ICLASS="FIRSTTERM">gzipped</I> ones.</P></TD></TR></TABLE></DIV></DD><DT><ANAME="SQREF"></A><BCLASS="COMMAND">sq</B></DT><DD><P>Yet another compression (<BCLASS="COMMAND">sq</B>ueeze)	      utility, a filter that works only on sorted	      ASCII word lists. It uses the standard invocation	      syntax for a filter, <BCLASS="COMMAND">sq &#60; input-file &#62;	      output-file</B>.  Fast, but not nearly as efficient	      as <AHREF="filearchiv.html#GZIPREF">gzip</A>.  The corresponding	      uncompression filter is <BCLASS="COMMAND">unsq</B>, invoked	      like <BCLASS="COMMAND">sq</B>.</P><DIVCLASS="TIP"><TABLECLASS="TIP"WIDTH="90%"BORDER="0"><TR><TDWIDTH="25"ALIGN="CENTER"VALIGN="TOP"><IMGSRC="common/tip.png"HSPACE="5"ALT="Tip"></TD><TDALIGN="LEFT"VALIGN="TOP"><P>The output of <BCLASS="COMMAND">sq</B> may be	        piped to <BCLASS="COMMAND">gzip</B> for further		compression.</P></TD></TR></TABLE></DIV></DD><DT><ANAME="ZIPREF"></A><BCLASS="COMMAND">zip</B>, <BCLASS="COMMAND">unzip</B></DT><DD><P>Cross-platform file archiving and compression utility	      compatible with DOS <ICLASS="FIRSTTERM">pkzip.exe</I>.	      <SPANCLASS="QUOTE">"Zipped"</SPAN> archives seem to be a more	      common medium of file exchange on the Internet than	      <SPANCLASS="QUOTE">"tarballs."</SPAN></P></DD><DT><ANAME="UNARCREF"></A><BCLASS="COMMAND">unarc</B>, <BCLASS="COMMAND">unarj</B>, <BCLASS="COMMAND">unrar</B></DT><DD><P>These Linux utilities permit unpacking archives	      compressed with the DOS <ICLASS="FIRSTTERM">arc.exe</I>,	      <ICLASS="FIRSTTERM">arj.exe</I>, and	      <ICLASS="FIRSTTERM">rar.exe</I> programs.</P></DD><DT><ANAME="LZMAREF"></A><BCLASS="COMMAND">lzma</B>, <BCLASS="COMMAND">unlzma</B>, <BCLASS="COMMAND">lzcat</B></DT><DD><P>Highly efficient Lempel-Ziv-Markov compression.	      The syntax of <ICLASS="FIRSTTERM">lzma</I> is similar to              that of <ICLASS="FIRSTTERM">gzip</I>. The <AHREF="http://www.7-zip.org/sdk.html"TARGET="_top">7-zip Website</A>              has more information.</P></DD></DL></DIV><DIVCLASS="VARIABLELIST"><P><B><ANAME="FAINFORMATION1"></A>File Information</B></P><DL><DT><ANAME="FILEREF"></A><BCLASS="COMMAND">file</B></DT><DD><P>A utility for identifying file types. The command	      <TTCLASS="USERINPUT"><B>file file-name</B></TT> will return a	      file specification for <TTCLASS="FILENAME">file-name</TT>,	      such as <TTCLASS="COMPUTEROUTPUT">ascii text</TT> or	      <TTCLASS="COMPUTEROUTPUT">data</TT>. It references	      the <AHREF="sha-bang.html#MAGNUMREF">magic numbers</A>	      found in <TTCLASS="FILENAME">/usr/share/magic</TT>,	      <TTCLASS="FILENAME">/etc/magic</TT>, or	      <TTCLASS="FILENAME">/usr/lib/magic</TT>, depending on the	      Linux/UNIX distribution.</P><P>The <TTCLASS="OPTION">-f</TT> option causes	      <BCLASS="COMMAND">file</B> to run in <AHREF="timedate.html#BATCHPROCREF">batch</A> mode, to read from	      a designated file a list of filenames to analyze. The	      <TTCLASS="OPTION">-z</TT> option, when used on a compressed	      target file, forces an attempt to analyze the uncompressed	      file type.</P><P>	      <TABLEBORDER="0"BGCOLOR="#E0E0E0"WIDTH="90%"><TR><TD><PRECLASS="SCREEN"> <TTCLASS="PROMPT">bash$ </TT><TTCLASS="USERINPUT"><B>file test.tar.gz</B></TT> <TTCLASS="COMPUTEROUTPUT">test.tar.gz: gzip compressed data, deflated, last modified: Sun Sep 16 13:34:51 2001, os: Unix</TT>  <TTCLASS="PROMPT">bash </TT><TTCLASS="USERINPUT"><B>file -z test.tar.gz</B></TT> <TTCLASS="COMPUTEROUTPUT">test.tar.gz: GNU tar archive (gzip compressed data, deflated, last modified: Sun Sep 16 13:34:51 2001, os: Unix)</TT> 	      </PRE></TD></TR></TABLE>	    </P><P>	      <TABLEBORDER="0"BGCOLOR="#E0E0E0"WIDTH="90%"><TR><TD><PRECLASS="PROGRAMLISTING">   1&nbsp;# Find sh and Bash scripts in a given directory:   2&nbsp;   3&nbsp;DIRECTORY=/usr/local/bin   4&nbsp;KEYWORD=Bourne   5&nbsp;# Bourne and Bourne-Again shell scripts   6&nbsp;   7&nbsp;file $DIRECTORY/* | fgrep $KEYWORD   8&nbsp;   9&nbsp;# Output:  10&nbsp;  11&nbsp;# /usr/local/bin/burn-cd:          Bourne-Again shell script text executable  12&nbsp;# /usr/local/bin/burnit:           Bourne-Again shell script text executable  13&nbsp;# /usr/local/bin/cassette.sh:      Bourne shell script text executable  14&nbsp;# /usr/local/bin/copy-cd:          Bourne-Again shell script text executable  15&nbsp;# . . .</PRE></TD></TR></TABLE>	    </P><DIVCLASS="EXAMPLE"><HR><ANAME="STRIPC"></A><P><B>Example 15-31. Stripping comments from C program files</B></P><TABLEBORDER="0"BGCOLOR="#E0E0E0"WIDTH="90%"><TR><TD><PRECLASS="PROGRAMLISTING">   1&nbsp;#!/bin/bash   2&nbsp;# strip-comment.sh: Strips out the comments (/* COMMENT */) in a C program.   3&nbsp;   4&nbsp;E_NOARGS=0   5&nbsp;E_ARGERROR=66   6&nbsp;E_WRONG_FILE_TYPE=67   7&nbsp;   8&nbsp;if [ $# -eq "$E_NOARGS" ]   9&nbsp;then  10&nbsp;  echo "Usage: `basename $0` C-program-file" &#62;&#38;2 # Error message to stderr.  11&nbsp;  exit $E_ARGERROR  12&nbsp;fi    13&nbsp;  14&nbsp;# Test for correct file type.  15&nbsp;type=`file $1 | awk '{ print $2, $3, $4, $5 }'`  16&nbsp;# "file $1" echoes file type . . .  17&nbsp;# Then awk removes the first field, the filename . . .  18&nbsp;# Then the result is fed into the variable "type."  19&nbsp;correct_type="ASCII C program text"  20&nbsp;  21&nbsp;if [ "$type" != "$correct_type" ]  22&nbsp;then  23&nbsp;  echo  24&nbsp;  echo "This script works on C program files only."  25&nbsp;  echo  26&nbsp;  exit $E_WRONG_FILE_TYPE  27&nbsp;fi    28&nbsp;  29&nbsp;  30&nbsp;# Rather cryptic sed script:  31&nbsp;#--------  32&nbsp;sed '  33&nbsp;/^\/\*/d  34&nbsp;/.*\*\//d  35&nbsp;' $1  36&nbsp;#--------  37&nbsp;# Easy to understand if you take several hours to learn sed fundamentals.  38&nbsp;  39&nbsp;  40&nbsp;#  Need to add one more line to the sed script to deal with  41&nbsp;#+ case where line of code has a comment following it on same line.  42&nbsp;#  This is left as a non-trivial exercise.  43&nbsp;  44&nbsp;#  Also, the above code deletes non-comment lines with a "*/" . . .  45&nbsp;#+ not a desirable result.  46&nbsp;  47&nbsp;exit 0  48&nbsp;  49&nbsp;  50&nbsp;# ----------------------------------------------------------------  51&nbsp;# Code below this line will not execute because of 'exit 0' above.  52&nbsp;  53&nbsp;# Stephane Chazelas suggests the following alternative:  54&nbsp;  55&nbsp;usage() {  56&nbsp;  echo "Usage: `basename $0` C-program-file" &#62;&#38;2  57&nbsp;  exit 1  58&nbsp;}  59&nbsp;  60&nbsp;WEIRD=`echo -n -e '\377'`   # or WEIRD=$'\377'  61&nbsp;[[ $# -eq 1 ]] || usage  62&nbsp;case `file "$1"` in  63&nbsp;  *"C program text"*) sed -e "s%/\*%${WEIRD}%g;s%\*/%${WEIRD}%g" "$1" \  64&nbsp;     | tr '\377\n' '\n\377' \  65&nbsp;     | sed -ne 'p;n' \  66&nbsp;     | tr -d '\n' | tr '\377' '\n';;  67&nbsp;  *) usage;;  68&nbsp;esac  69&nbsp;  70&nbsp;#  This is still fooled by things like:  71&nbsp;#  printf("/*");  72&nbsp;#  or  73&nbsp;#  /*  /* buggy embedded comment */  74&nbsp;#  75&nbsp;#  To handle all special cases (comments in strings, comments in string  76&nbsp;#+ where there is a \", \\" ...),  77&nbsp;#+ the only way is to write a C parser (using lex or yacc perhaps?).  78&nbsp;  79&nbsp;exit 0</PRE></TD></TR></TABLE><HR></DIV></DD><DT><ANAME="WHICHREF"></A><BCLASS="COMMAND">which</B></DT><DD><P><BCLASS="COMMAND">which command</B> gives the full path	      to <SPANCLASS="QUOTE">"command."</SPAN> This is useful for finding	      out whether a particular command or utility is installed	      on the system.</P><P><TTCLASS="USERINPUT"><B>$bash which rm</B></TT><TABLEBORDER="0"BGCOLOR="#E0E0E0"WIDTH="90%"><TR><TD><PRECLASS="SCREEN"> <TTCLASS="COMPUTEROUTPUT">/usr/bin/rm</TT></PRE></TD></TR></TABLE>	  </P><P>For an interesting use of this command, see <AHREF="colorizing.html#HORSERACE">Example 33-14</A>.</P></DD><DT><ANAME="WHEREISREF"></A><BCLASS="COMMAND">whereis</B></DT><DD><P>Similar to <BCLASS="COMMAND">which</B>, above,	      <BCLASS="COMMAND">whereis command</B> gives the	      full path to <SPANCLASS="QUOTE">"command,"</SPAN> but also to its	      <AHREF="external.html#MANREF">manpage</A>.</P><P><TTCLASS="USERINPUT"><B>$bash whereis rm</B></TT><TABLEBORDER="0"BGCOLOR="#E0E0E0"WIDTH="90%"><TR><TD><PRECLASS="SCREEN"> <TTCLASS="COMPUTEROUTPUT">rm: /bin/rm /usr/share/man/man1/rm.1.bz2</TT></PRE></TD></TR></TABLE>	  </P></DD><DT><ANAME="WHATISREF"></A><BCLASS="COMMAND">whatis</B></DT><DD><P><BCLASS="COMMAND">whatis command</B> looks up	      <SPANCLASS="QUOTE"

⌨️ 快捷键说明

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