📄 filearchiv.html
字号:
><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 < input-file > 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 # Find sh and Bash scripts in a given directory: 2 3 DIRECTORY=/usr/local/bin 4 KEYWORD=Bourne 5 # Bourne and Bourne-Again shell scripts 6 7 file $DIRECTORY/* | fgrep $KEYWORD 8 9 # Output: 10 11 # /usr/local/bin/burn-cd: Bourne-Again shell script text executable 12 # /usr/local/bin/burnit: Bourne-Again shell script text executable 13 # /usr/local/bin/cassette.sh: Bourne shell script text executable 14 # /usr/local/bin/copy-cd: Bourne-Again shell script text executable 15 # . . .</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 #!/bin/bash 2 # strip-comment.sh: Strips out the comments (/* COMMENT */) in a C program. 3 4 E_NOARGS=0 5 E_ARGERROR=66 6 E_WRONG_FILE_TYPE=67 7 8 if [ $# -eq "$E_NOARGS" ] 9 then 10 echo "Usage: `basename $0` C-program-file" >&2 # Error message to stderr. 11 exit $E_ARGERROR 12 fi 13 14 # Test for correct file type. 15 type=`file $1 | awk '{ print $2, $3, $4, $5 }'` 16 # "file $1" echoes file type . . . 17 # Then awk removes the first field, the filename . . . 18 # Then the result is fed into the variable "type." 19 correct_type="ASCII C program text" 20 21 if [ "$type" != "$correct_type" ] 22 then 23 echo 24 echo "This script works on C program files only." 25 echo 26 exit $E_WRONG_FILE_TYPE 27 fi 28 29 30 # Rather cryptic sed script: 31 #-------- 32 sed ' 33 /^\/\*/d 34 /.*\*\//d 35 ' $1 36 #-------- 37 # Easy to understand if you take several hours to learn sed fundamentals. 38 39 40 # Need to add one more line to the sed script to deal with 41 #+ case where line of code has a comment following it on same line. 42 # This is left as a non-trivial exercise. 43 44 # Also, the above code deletes non-comment lines with a "*/" . . . 45 #+ not a desirable result. 46 47 exit 0 48 49 50 # ---------------------------------------------------------------- 51 # Code below this line will not execute because of 'exit 0' above. 52 53 # Stephane Chazelas suggests the following alternative: 54 55 usage() { 56 echo "Usage: `basename $0` C-program-file" >&2 57 exit 1 58 } 59 60 WEIRD=`echo -n -e '\377'` # or WEIRD=$'\377' 61 [[ $# -eq 1 ]] || usage 62 case `file "$1"` in 63 *"C program text"*) sed -e "s%/\*%${WEIRD}%g;s%\*/%${WEIRD}%g" "$1" \ 64 | tr '\377\n' '\n\377' \ 65 | sed -ne 'p;n' \ 66 | tr -d '\n' | tr '\377' '\n';; 67 *) usage;; 68 esac 69 70 # This is still fooled by things like: 71 # printf("/*"); 72 # or 73 # /* /* buggy embedded comment */ 74 # 75 # To handle all special cases (comments in strings, comments in string 76 #+ where there is a \", \\" ...), 77 #+ the only way is to write a C parser (using lex or yacc perhaps?). 78 79 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 + -