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

📄 filearchiv.html

📁 Shall高级编程
💻 HTML
📖 第 1 页 / 共 5 页
字号:
>"command"</SPAN> in the	      <TTCLASS="REPLACEABLE"><I>whatis</I></TT> database. This is useful	      for identifying system commands and important configuration	      files. Consider it a simplified <BCLASS="COMMAND">man</B>	      command.</P><P><TTCLASS="USERINPUT"><B>$bash whatis whatis</B></TT><TABLEBORDER="0"BGCOLOR="#E0E0E0"WIDTH="90%"><TR><TD><PRECLASS="SCREEN"> <TTCLASS="COMPUTEROUTPUT">whatis               (1)  - search the whatis database for complete words</TT></PRE></TD></TR></TABLE>	  </P><DIVCLASS="EXAMPLE"><HR><ANAME="WHAT"></A><P><B>Example 15-32. Exploring <TTCLASS="FILENAME">/usr/X11R6/bin</TT></B></P><TABLEBORDER="0"BGCOLOR="#E0E0E0"WIDTH="90%"><TR><TD><PRECLASS="PROGRAMLISTING">   1&nbsp;#!/bin/bash   2&nbsp;   3&nbsp;# What are all those mysterious binaries in /usr/X11R6/bin?   4&nbsp;   5&nbsp;DIRECTORY="/usr/X11R6/bin"   6&nbsp;# Try also "/bin", "/usr/bin", "/usr/local/bin", etc.   7&nbsp;   8&nbsp;for file in $DIRECTORY/*   9&nbsp;do  10&nbsp;  whatis `basename $file`   # Echoes info about the binary.  11&nbsp;done  12&nbsp;  13&nbsp;exit 0  14&nbsp;  15&nbsp;# You may wish to redirect output of this script, like so:  16&nbsp;# ./what.sh &#62;&#62;whatis.db  17&nbsp;# or view it a page at a time on stdout,  18&nbsp;# ./what.sh | less</PRE></TD></TR></TABLE><HR></DIV><P>See also <AHREF="loops.html#FILEINFO">Example 10-3</A>.</P></DD><DT><ANAME="VDIRREF"></A><BCLASS="COMMAND">vdir</B></DT><DD><P>Show a detailed directory listing. The effect is similar to	      <AHREF="external.html#LSREF">ls -lb</A>.</P><P>This is one of the GNU	    <ICLASS="FIRSTTERM">fileutils</I>.</P><P>	      <TABLEBORDER="0"BGCOLOR="#E0E0E0"WIDTH="90%"><TR><TD><PRECLASS="SCREEN"> <TTCLASS="PROMPT">bash$ </TT><TTCLASS="USERINPUT"><B>vdir</B></TT> <TTCLASS="COMPUTEROUTPUT">total 10 -rw-r--r--    1 bozo  bozo      4034 Jul 18 22:04 data1.xrolo -rw-r--r--    1 bozo  bozo      4602 May 25 13:58 data1.xrolo.bak -rw-r--r--    1 bozo  bozo       877 Dec 17  2000 employment.xrolo</TT>  <TTCLASS="PROMPT">bash </TT><TTCLASS="USERINPUT"><B>ls -l</B></TT> <TTCLASS="COMPUTEROUTPUT">total 10 -rw-r--r--    1 bozo  bozo      4034 Jul 18 22:04 data1.xrolo -rw-r--r--    1 bozo  bozo      4602 May 25 13:58 data1.xrolo.bak -rw-r--r--    1 bozo  bozo       877 Dec 17  2000 employment.xrolo</TT> 	      </PRE></TD></TR></TABLE>	      </P></DD><DT><ANAME="LOCATEREF"></A><BCLASS="COMMAND">locate</B>, <ANAME="SLOCATEREF"></A><BCLASS="COMMAND">slocate</B></DT><DD><P>The <BCLASS="COMMAND">locate</B> command searches for files using a	      database stored for just that purpose. The	      <BCLASS="COMMAND">slocate</B> command is the secure version of	      <BCLASS="COMMAND">locate</B> (which may be aliased to	      <BCLASS="COMMAND">slocate</B>).</P><P><TTCLASS="USERINPUT"><B>$bash locate hickson</B></TT><TABLEBORDER="0"BGCOLOR="#E0E0E0"WIDTH="90%"><TR><TD><PRECLASS="SCREEN"> <TTCLASS="COMPUTEROUTPUT">/usr/lib/xephem/catalogs/hickson.edb</TT></PRE></TD></TR></TABLE></P></DD><DT><ANAME="READLINKREF"></A><BCLASS="COMMAND">readlink</B></DT><DD><P>Disclose the file that a symbolic link points to.</P><P>	      <TABLEBORDER="0"BGCOLOR="#E0E0E0"WIDTH="90%"><TR><TD><PRECLASS="SCREEN"> <TTCLASS="PROMPT">bash$ </TT><TTCLASS="USERINPUT"><B>readlink /usr/bin/awk</B></TT> <TTCLASS="COMPUTEROUTPUT">../../bin/gawk</TT> 	      </PRE></TD></TR></TABLE>	    </P></DD><DT><ANAME="STRINGSREF"></A><BCLASS="COMMAND">strings</B></DT><DD><P>Use the <BCLASS="COMMAND">strings</B> command to find	      printable strings in a binary or data file. It will list	      sequences of printable characters found in the target	      file. This might be handy for a quick 'n dirty examination	      of a core dump or for looking at an unknown graphic image	      file (<TTCLASS="USERINPUT"><B>strings image-file | more</B></TT> might	      show something like <ICLASS="FIRSTTERM">JFIF</I>,	      which would identify the file as a <ICLASS="FIRSTTERM">jpeg</I>	      graphic). In a script, you would probably	      parse the output of <BCLASS="COMMAND">strings</B>	      with <AHREF="textproc.html#GREPREF">grep</A> or <AHREF="sedawk.html#SEDREF">sed</A>. See <AHREF="loops.html#BINGREP">Example 10-7</A>	      and <AHREF="loops.html#FINDSTRING">Example 10-9</A>.</P><DIVCLASS="EXAMPLE"><HR><ANAME="WSTRINGS"></A><P><B>Example 15-33. An <SPANCLASS="QUOTE">"improved"</SPAN>	      <ICLASS="FIRSTTERM">strings</I> command</B></P><TABLEBORDER="0"BGCOLOR="#E0E0E0"WIDTH="90%"><TR><TD><PRECLASS="PROGRAMLISTING">   1&nbsp;#!/bin/bash   2&nbsp;# wstrings.sh: "word-strings" (enhanced "strings" command)   3&nbsp;#   4&nbsp;#  This script filters the output of "strings" by checking it   5&nbsp;#+ against a standard word list file.   6&nbsp;#  This effectively eliminates gibberish and noise,   7&nbsp;#+ and outputs only recognized words.   8&nbsp;   9&nbsp;# ===========================================================  10&nbsp;#                 Standard Check for Script Argument(s)  11&nbsp;ARGS=1  12&nbsp;E_BADARGS=65  13&nbsp;E_NOFILE=66  14&nbsp;  15&nbsp;if [ $# -ne $ARGS ]  16&nbsp;then  17&nbsp;  echo "Usage: `basename $0` filename"  18&nbsp;  exit $E_BADARGS  19&nbsp;fi  20&nbsp;  21&nbsp;if [ ! -f "$1" ]                      # Check if file exists.  22&nbsp;then  23&nbsp;    echo "File \"$1\" does not exist."  24&nbsp;    exit $E_NOFILE  25&nbsp;fi  26&nbsp;# ===========================================================  27&nbsp;  28&nbsp;  29&nbsp;MINSTRLEN=3                           #  Minimum string length.  30&nbsp;WORDFILE=/usr/share/dict/linux.words  #  Dictionary file.  31&nbsp;                                      #  May specify a different  32&nbsp;                                      #+ word list file  33&nbsp;                                      #+ of one-word-per-line format.  34&nbsp;  35&nbsp;  36&nbsp;wlist=`strings "$1" | tr A-Z a-z | tr '[:space:]' Z | \  37&nbsp;tr -cs '[:alpha:]' Z | tr -s '\173-\377' Z | tr Z ' '`  38&nbsp;  39&nbsp;# Translate output of 'strings' command with multiple passes of 'tr'.  40&nbsp;#  "tr A-Z a-z"  converts to lowercase.  41&nbsp;#  "tr '[:space:]'"  converts whitespace characters to Z's.  42&nbsp;#  "tr -cs '[:alpha:]' Z"  converts non-alphabetic characters to Z's,  43&nbsp;#+ and squeezes multiple consecutive Z's.  44&nbsp;#  "tr -s '\173-\377' Z"  converts all characters past 'z' to Z's  45&nbsp;#+ and squeezes multiple consecutive Z's,  46&nbsp;#+ which gets rid of all the weird characters that the previous  47&nbsp;#+ translation failed to deal with.  48&nbsp;#  Finally, "tr Z ' '" converts all those Z's to whitespace,  49&nbsp;#+ which will be seen as word separators in the loop below.  50&nbsp;  51&nbsp;#  ****************************************************************  52&nbsp;#  Note the technique of feeding the output of 'tr' back to itself,  53&nbsp;#+ but with different arguments and/or options on each pass.  54&nbsp;#  ****************************************************************  55&nbsp;  56&nbsp;  57&nbsp;for word in $wlist                    # Important:  58&nbsp;                                      # $wlist must not be quoted here.  59&nbsp;                                      # "$wlist" does not work.  60&nbsp;                                      # Why not?  61&nbsp;do  62&nbsp;  63&nbsp;  strlen=${#word}                     # String length.  64&nbsp;  if [ "$strlen" -lt "$MINSTRLEN" ]   # Skip over short strings.  65&nbsp;  then  66&nbsp;    continue  67&nbsp;  fi  68&nbsp;  69&nbsp;  grep -Fw $word "$WORDFILE"          #  Match whole words only.  70&nbsp;#      ^^^                            #  "Fixed strings" and  71&nbsp;                                      #+ "whole words" options.   72&nbsp;  73&nbsp;done    74&nbsp;  75&nbsp;  76&nbsp;exit $?</PRE></TD></TR></TABLE><HR></DIV></DD></DL></DIV><DIVCLASS="VARIABLELIST"><P><B><ANAME="COMPARISONN1"></A>Comparison</B></P><DL><DT><ANAME="DIFFREF"></A><BCLASS="COMMAND">diff</B>, <BCLASS="COMMAND">patch</B></DT><DD><P><BCLASS="COMMAND">diff</B>: flexible file comparison	      utility. It compares the target files line-by-line	      sequentially.  In some applications, such as comparing	      word dictionaries, it may be helpful to filter the	      files through <AHREF="textproc.html#SORTREF">sort</A>	      and <BCLASS="COMMAND">uniq</B> before piping them	      to <BCLASS="COMMAND">diff</B>. <TTCLASS="USERINPUT"><B>diff file-1	      file-2</B></TT> outputs the lines in the files that	      differ, with carets showing which file each particular	      line belongs to.</P><P>The <TTCLASS="OPTION">--side-by-side</TT> option to	    <BCLASS="COMMAND">diff</B> outputs each compared file, line by	    line, in separate columns, with non-matching lines marked. The	    <TTCLASS="OPTION">-c</TT> and <TTCLASS="OPTION">-u</TT> options likewise	    make the output of the command easier to interpret.</P><P>There are available various fancy frontends for	    <BCLASS="COMMAND">diff</B>, such as <BCLASS="COMMAND">sdiff</B>,	    <BCLASS="COMMAND">wdiff</B>, <BCLASS="COMMAND">xdiff</B>, and	    <BCLASS="COMMAND">mgdiff</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">diff</B> command returns an exit	    status of 0 if the compared files are identical, and 1 if	    they differ. This permits use of <BCLASS="COMMAND">diff</B>	    in a test construct within a shell script (see	    below).</P></TD></TR></TABLE></DIV><P>A common use for <BCLASS="COMMAND">diff</B> is generating	      difference files to be used with <BCLASS="COMMAND">patch</B>	      The <TTCLASS="OPTION">-e</TT> option outputs files suitable	      for <BCLASS="COMMAND">ed</B> or <BCLASS="COMMAND">ex</B>	      scripts.</P><P><ANAME="PATCHREF"></A></P><P><BCLASS="COMMAND">patch</B>: flexible versioning	      utility. Given a difference file generated by	      <BCLASS="COMMAND">diff</B>, <BCLASS="COMMAND">patch</B> can	      upgrade a previous version of a package to a newer version.	      It is much more convenient to distribute a relatively	      small <SPANCLASS="QUOTE">"diff"</SPAN> file than the entire body of a	      newly revised package. Kernel <SPANCLASS="QUOTE">"patches"</SPAN> have	      become the preferred method of distributing the frequent	      releases of the Linux kernel.</P><P><TABLEBORDER="0"BGCOLOR="#E0E0E0"WIDTH="90%"><TR><TD><PRECLASS="PROGRAMLISTING">   1&nbsp;patch -p1 &#60;patch-file   2&nbsp;# Takes all the changes listed in 'patch-file'   3&nbsp;# and applies them to the files referenced therein.   4&nbsp;# This upgrades to a newer version of the package.</PRE></TD></TR></TABLE></P><P>Patching the kernel:</P><P><TABLEBORDER="0"BGCOLOR="#E0E0E0"WIDTH="90%"><TR><TD><PRECLASS="PROGRAMLISTING">   1&nbsp;cd /usr/src   2&nbsp;gzip -cd patchXX.gz | patch -p0   3&nbsp;# Upgrading kernel source using 'patch'.   4&nbsp;# From the Linux kernel docs "README",   5&nbsp;# by anonymous author (Alan Cox?).</PRE></TD></TR></TABLE></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 <BCLASS="COMMAND">diff</B> command can also	      recursively compare directories (for the filenames	      present).</P><P>	      <TABLEBORDER="0"BGCOLOR="#E0E0E0"WIDTH="90%"><TR><TD><PRECLASS="SCREEN"> <TTCLASS="PROMPT">bash$ </TT><TTCLASS="USERINPUT"><B>diff -r ~/notes1 ~/notes2</B></TT> <TTCLASS="COMPUTEROUTPUT">Only in /home/bozo/notes1: file02 Only in /home/bozo/notes1: file03 Only in /home/bozo/notes2: file04</TT> 	      </PRE></TD></TR></TABLE>	    </P></TD></TR></TABLE></DIV><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><ANAME="ZDIFFREF"></A></P><P>Use <BCLASS="COMMAND">zdiff</B> to compare	       <ICLASS="FIRSTTERM">gzipped</I> files.</P></TD></TR></TABLE></DIV><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><ANAME="DIFFSTATREF"></A></P><P>Use <BCLASS="COMMAND">diffstat</B> to create	       a histogram (point-distribution graph) of output from	       <BCLASS="COMMAND">diff</B>.</P></TD></TR></TABLE></DIV></DD><DT><ANAME="DIFF3REF"></A><BCLASS="COMMAND">diff3</B></DT><DD><P>An extended version of <BCLASS="COMMAND">diff</B> that compares	      three files at a time. This command returns an exit value	      of 0 upon successful execution, but unfortunately this gives	      no information about the results of the comparison.</P><P>	      <TABLEBORDER="0"BGCOLOR="#E0E0E0"WIDTH="90%"><TR><TD><PRECLASS="SCREEN"> <TTCLASS="PROMPT">bash$ </TT><TTCLASS="USERINPUT"><B>diff3 file-1 file-2 file-3</B

⌨️ 快捷键说明

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