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

📄 filearchiv.html

📁 Shall高级编程
💻 HTML
📖 第 1 页 / 共 5 页
字号:
  49&nbsp;    then  50&nbsp;      filename[n]=$( echo ${record[$n]} | awk '{ print $2 }' )  51&nbsp;      #  md5sum writes records backwards,  52&nbsp;      #+ checksum first, then filename.  53&nbsp;      checksum[n]=$( md5sum "${filename[n]}" )  54&nbsp;  55&nbsp;  56&nbsp;      if [ "${record[n]}" = "${checksum[n]}" ]  57&nbsp;      then  58&nbsp;        echo "${filename[n]} unchanged."  59&nbsp;  60&nbsp;      elif [ "`basename ${filename[n]}`" != "$dbfile" ]  61&nbsp;             #  Skip over checksum database file,  62&nbsp;             #+ as it will change with each invocation of script.  63&nbsp;	     #  ---  64&nbsp;	     #  This unfortunately means that when running  65&nbsp;	     #+ this script on $PWD, tampering with the  66&nbsp;	     #+ checksum database file will not be detected.  67&nbsp;	     #  Exercise: Fix this.  68&nbsp;	then  69&nbsp;          echo "${filename[n]} : CHECKSUM ERROR!"  70&nbsp;        # File has been changed since last checked.  71&nbsp;      fi  72&nbsp;  73&nbsp;      fi  74&nbsp;  75&nbsp;  76&nbsp;  77&nbsp;    let "n+=1"  78&nbsp;  done &#60;"$dbfile"       # Read from checksum database file.   79&nbsp;  80&nbsp;}    81&nbsp;  82&nbsp;# =================================================== #  83&nbsp;# main ()  84&nbsp;  85&nbsp;if [ -z  "$1" ]  86&nbsp;then  87&nbsp;  directory="$PWD"      #  If not specified,  88&nbsp;else                    #+ use current working directory.  89&nbsp;  directory="$1"  90&nbsp;fi    91&nbsp;  92&nbsp;clear                   # Clear screen.  93&nbsp;echo " Running file integrity check on $directory"  94&nbsp;echo  95&nbsp;  96&nbsp;# ------------------------------------------------------------------ #  97&nbsp;  if [ ! -r "$dbfile" ] # Need to create database file?  98&nbsp;  then  99&nbsp;    echo "Setting up database file, \""$directory"/"$dbfile"\"."; echo 100&nbsp;    set_up_database 101&nbsp;  fi   102&nbsp;# ------------------------------------------------------------------ # 103&nbsp; 104&nbsp;check_database          # Do the actual work. 105&nbsp; 106&nbsp;echo  107&nbsp; 108&nbsp;#  You may wish to redirect the stdout of this script to a file, 109&nbsp;#+ especially if the directory checked has many files in it. 110&nbsp; 111&nbsp;exit 0 112&nbsp; 113&nbsp;#  For a much more thorough file integrity check, 114&nbsp;#+ consider the "Tripwire" package, 115&nbsp;#+ http://sourceforge.net/projects/tripwire/. 116&nbsp;</PRE></TD></TR></TABLE><HR></DIV><P>Also see <AHREF="contributed-scripts.html#DIRECTORYINFO">Example A-20</A>, <AHREF="colorizing.html#HORSERACE">Example 33-14</A>, and <AHREF="string-manipulation.html#RANDSTRING">Example 9-11</A> for	    creative uses of the <BCLASS="COMMAND">md5sum</B> command.</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>	    There have been reports that the 128-bit	    <BCLASS="COMMAND">md5sum</B> can be cracked, so the more secure	    160-bit <BCLASS="COMMAND">sha1sum</B> is a welcome new addition	    to the checksum toolkit.          </P><TABLEBORDER="0"BGCOLOR="#E0E0E0"WIDTH="90%"><TR><TD><PRECLASS="SCREEN"> <TTCLASS="PROMPT">bash$ </TT><TTCLASS="USERINPUT"><B>md5sum testfile</B></TT> <TTCLASS="COMPUTEROUTPUT">e181e2c8720c60522c4c4c981108e367  testfile</TT>   <TTCLASS="PROMPT">bash$ </TT><TTCLASS="USERINPUT"><B>sha1sum testfile</B></TT> <TTCLASS="COMPUTEROUTPUT">5d7425a9c08a66c3177f1e31286fa40986ffc996  testfile</TT> 	      </PRE></TD></TR></TABLE></TD></TR></TABLE></DIV><P>Security consultants have demonstrated that even	      <BCLASS="COMMAND">sha1sum</B> can be compromised. Fortunately,	      newer Linux distros include longer bit-length	      <BCLASS="COMMAND">sha224sum</B>,	      <BCLASS="COMMAND">sha256sum</B>,	      <BCLASS="COMMAND">sha384sum</B>, and	      <BCLASS="COMMAND">sha512sum</B> commands.</P></DD><DT><ANAME="SHREDREF"></A><BCLASS="COMMAND">shred</B></DT><DD><P>Securely erase a file by overwriting it multiple times with	      random bit patterns before deleting it. This command has	      the same effect as <AHREF="extmisc.html#BLOTOUT">Example 15-58</A>, but does it	      in a more thorough and elegant manner.</P><P>This is one of the GNU	    <ICLASS="FIRSTTERM">fileutils</I>.</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>Advanced forensic technology may still be able to	      recover the contents of a file, even after application of	      <BCLASS="COMMAND">shred</B>.</P></TD></TR></TABLE></DIV></DD><DT><ANAME="UUENCODEREF"></A><BCLASS="COMMAND">uuencode</B></DT><DD><P>This utility encodes binary files (images, sound files,	      compressed files, etc.) into ASCII characters, making them	      suitable for transmission in the body of an e-mail message or in a	      newsgroup posting. This is especially useful where MIME	      (multimedia) encoding is not available.</P></DD><DT><ANAME="UUDECODEREF"></A><BCLASS="COMMAND">uudecode</B></DT><DD><P>This reverses the encoding, decoding	      <ICLASS="FIRSTTERM">uuencoded</I> files back into the	      original binaries.</P><DIVCLASS="EXAMPLE"><HR><ANAME="EX52"></A><P><B>Example 15-38. Uudecoding encoded files</B></P><TABLEBORDER="0"BGCOLOR="#E0E0E0"WIDTH="90%"><TR><TD><PRECLASS="PROGRAMLISTING">   1&nbsp;#!/bin/bash   2&nbsp;# Uudecodes all uuencoded files in current working directory.   3&nbsp;   4&nbsp;lines=35        # Allow 35 lines for the header (very generous).   5&nbsp;   6&nbsp;for File in *   # Test all the files in $PWD.   7&nbsp;do   8&nbsp;  search1=`head -n $lines $File | grep begin | wc -w`   9&nbsp;  search2=`tail -n $lines $File | grep end | wc -w`  10&nbsp;  #  Uuencoded files have a "begin" near the beginning,  11&nbsp;  #+ and an "end" near the end.  12&nbsp;  if [ "$search1" -gt 0 ]  13&nbsp;  then  14&nbsp;    if [ "$search2" -gt 0 ]  15&nbsp;    then  16&nbsp;      echo "uudecoding - $File -"  17&nbsp;      uudecode $File  18&nbsp;    fi    19&nbsp;  fi  20&nbsp;done    21&nbsp;  22&nbsp;#  Note that running this script upon itself fools it  23&nbsp;#+ into thinking it is a uuencoded file,  24&nbsp;#+ because it contains both "begin" and "end".  25&nbsp;  26&nbsp;#  Exercise:  27&nbsp;#  --------  28&nbsp;#  Modify this script to check each file for a newsgroup header,  29&nbsp;#+ and skip to next if not found.  30&nbsp;  31&nbsp;exit 0</PRE></TD></TR></TABLE><HR></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>The <AHREF="textproc.html#FOLDREF">fold -s</A> command	    may be useful (possibly in a pipe) to process long uudecoded	    text messages downloaded from Usenet newsgroups.</P></TD></TR></TABLE></DIV></DD><DT><ANAME="MIMENCODEREF"></A><BCLASS="COMMAND">mimencode</B>, <ANAME="MMENCODEREF"></A><BCLASS="COMMAND">mmencode</B></DT><DD><P>The <BCLASS="COMMAND">mimencode</B> and	      <BCLASS="COMMAND">mmencode</B> commands process	      multimedia-encoded e-mail attachments. Although	      <ICLASS="FIRSTTERM">mail user agents</I> (such as	      <ICLASS="FIRSTTERM">pine</I> or <ICLASS="FIRSTTERM">kmail</I>)	      normally handle this automatically, these particular	      utilities permit manipulating such attachments manually from	      the command line or in <AHREF="timedate.html#BATCHPROCREF">batch	      processing mode</A> by means of a shell script.</P></DD><DT><ANAME="CRYPTREF"></A><BCLASS="COMMAND">crypt</B></DT><DD><P>At one time, this was the standard UNIX file encryption	      utility.              <ANAME="AEN11881"HREF="#FTN.AEN11881">[3]</A>	      Politically motivated government regulations	      prohibiting the export of encryption software resulted	      in the disappearance of <BCLASS="COMMAND">crypt</B>	      from much of the UNIX world, and it is still	      missing from most Linux distributions. Fortunately,	      programmers have come up with a number of decent	      alternatives to it, among them the author's very own <AHREF="ftp://metalab.unc.edu/pub/Linux/utils/file/cruft-0.2.tar.gz"TARGET="_top">cruft</A>	      (see <AHREF="contributed-scripts.html#ENCRYPTEDPW">Example A-4</A>).  </P></DD></DL></DIV><DIVCLASS="VARIABLELIST"><P><B><ANAME="FAMISC1"></A>Miscellaneous</B></P><DL><DT><ANAME="MKTEMPREF"></A><BCLASS="COMMAND">mktemp</B></DT><DD><P>Create a <ICLASS="FIRSTTERM">temporary file</I>	       <ANAME="AEN11903"HREF="#FTN.AEN11903">[4]</A>	      with a <SPANCLASS="QUOTE">"unique"</SPAN> filename. When invoked	      from the command line without additional arguments,	      it creates a zero-length file in the <TTCLASS="FILENAME">/tmp</TT> directory.</P><P>	      <TABLEBORDER="0"BGCOLOR="#E0E0E0"WIDTH="90%"><TR><TD><PRECLASS="SCREEN"> <TTCLASS="PROMPT">bash$ </TT><TTCLASS="USERINPUT"><B>mktemp</B></TT> <TTCLASS="COMPUTEROUTPUT">/tmp/tmp.zzsvql3154</TT> 	      </PRE></TD></TR></TABLE>	    </P><P><TABLEBORDER="0"BGCOLOR="#E0E0E0"WIDTH="90%"><TR><TD><PRECLASS="PROGRAMLISTING">   1&nbsp;PREFIX=filename   2&nbsp;tempfile=`mktemp $PREFIX.XXXXXX`   3&nbsp;#                        ^^^^^^ Need at least 6 placeholders   4&nbsp;#+                              in the filename template.   5&nbsp;#   If no filename template supplied,   6&nbsp;#+ "tmp.XXXXXXXXXX" is the default.   7&nbsp;   8&nbsp;echo "tempfile name = $tempfile"   9&nbsp;# tempfile name = filename.QA2ZpY  10&nbsp;#                 or something similar...  11&nbsp;  12&nbsp;#  Creates a file of that name in the current working directory  13&nbsp;#+ with 600 file permissions.  14&nbsp;#  A "umask 177" is therefore unnecessary,  15&nbsp;#+ but it's good programming practice anyhow.</PRE></TD></TR></TABLE></P></DD><DT><ANAME="MAKEREF"></A><BCLASS="COMMAND">make</B></DT><DD><P><ANAME="MAKEFILEREF"></A></P><P>Utility for building and compiling binary packages. 	      This can also be used for any set of operations that is	      triggered by incremental changes in source files.</P><P>The <BCLASS="COMMAND">make</B> command checks a	    <TTCLASS="FILENAME">Makefile</TT>, a list of file dependencies and	      operations to be carried out.</P><P>The <ICLASS="FIRSTTERM">make</I> utility is, in effect,	      a powerful scripting language similar in many ways to	      <ICLASS="FIRSTTERM">Bash</I>, but with the capability of	      recognizing <ICLASS="FIRSTTERM">dependencies</I>. For in-depth	      coverage of this useful tool set, see the <AHREF="http://www.gnu.org/manual/manual.html"TARGET="_top">GNU software	      documentation site</A>.</P></DD><DT><ANAME="INSTALLREF"></A><BCLASS="COMMAND">install</B></DT><DD><P>Special purpose file copying command, similar to	      <BCLASS="COMMAND">cp</B>, but capable of setting permissions	      and attributes of the copied files. This command seems	      tailormade for installing software packages, and as such it	      shows up frequently in <TTCLASS="FILENAME">Makefiles</TT>	      (in the <TTCLASS="REPLACEABLE"><I>make install :</I></TT>	      section). It could likewise find use in installation	      scripts.</P></DD><DT><ANAME="DOS2UNIXREF"></A><BCLASS="COMMAND">dos2unix</B></DT><DD><P>This utility, written by Benjamin Lin and collaborators,	      converts DOS-formatted text files (lines terminated by	      CR-LF) to UNIX format (lines terminated by LF only),	      and vice-versa.</P></DD><DT><ANAME="PTXREF"></A><BCLASS="COMMAND">ptx</B></DT><DD><P>The <BCLASS="COMMAND">ptx [targetfile]</B> command	      outputs a permuted index (cross-reference list) of the	      targetfile. This may be further filtered and formatted in a	      pipe, if necessary.</P></DD><DT><ANAME="MOREREF"></A><BCLASS="COMMAND">more</B>, <ANAME="LESSREF"></A><BCLASS="COMMAND">less</B></DT><DD><P>Pagers that display a text file or stream to	      <TTCLASS="FILENAME">stdout</TT>, one screenful at a time.	      These may be used to filter the output of	      <TTCLASS="FILENAME">stdout</TT> . . . or of a script.</P><P>	       An interesting application of <BCLASS="COMMAND">more</B>	       is to <SPANCLASS="QUOTE">"test drive"</SPAN> a command sequence,	       to forestall potentially unpleasant consequences.                 <TABLEBORDER="0"BGCOLOR="#E0E0E0"WIDTH="90%"><TR><TD><PRECLASS="PROGRAMLISTING">   1&nbsp;ls /home/bozo | awk '{print "rm -rf " $1}' | more   2&nbsp;#                                            ^^^^   3&nbsp;		    4&nbsp;# Testing the effect of the following (disastrous) command line:   5&nbsp;#      ls /home/bozo | awk '{print "rm -rf " $1}' | sh   6&nbsp;#      Hand off to the shell to execute . . .       ^^</PRE></TD></TR></TABLE>            </P></DD></DL></DIV></DIV><H3CLASS="FOOTNOTES">Notes</H3><TABLEBORDER="0"CLASS="FOOTNOTES"WIDTH="100%"><TR><TDALIGN="LEFT"VALIGN="TOP"WIDTH="5%"><ANAME="FTN.AEN10910"HREF="filearchiv.html#AEN10910">[1]</A></TD><TDALIGN="LEFT"VALIGN="TOP"WIDTH="95%"><P>An <ICLASS="FIRSTTERM">archive</I>,	        in the sense discussed here, is simply a set of related	        files stored in a single location.</P></TD></TR><TR><TDALIGN="LEFT"VALIGN="TOP"WIDTH="5%"><ANAME="FTN.AEN10921"HREF="filearchiv.html#AEN10921">[2]</A></TD><TDALIGN="LEFT"VALIGN="TOP"WIDTH="95%"><P>		    A <BCLASS="COMMAND">tar czvf archive_name.tar.gz *</B>		    <SPANCLASS="emphasis"><ICLASS="EMPHASIS">will</I></SPAN> include dotfiles in		    directories <SPANCLASS="emphasis"><ICLASS="EMPHASIS">below</I></SPAN> the current		    working directory. This is an undocumented GNU		    <BCLASS="COMMAND">tar</B> <SPANCLASS="QUOTE">"feature"</SPAN>.		  </P></TD></TR><TR><TDALIGN="LEFT"VALIGN="TOP"WIDTH="5%"><ANAME="FTN.AEN11881

⌨️ 快捷键说明

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