Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 12 Sep 2012 14:11:05 -0400 (EDT)
From:      vogelke+freebsd@pobox.com (Karl Vogel)
To:        freebsd-questions@freebsd.org
Subject:   Re: cksum entire dir??
Message-ID:  <20120912181105.77E05BEA6@kev.msw.wpafb.af.mil>
In-Reply-To: <20120912011725.GG3066@hs1.VERBENA> (message from Colin Barnabas on Tue, 11 Sep 2012 18:17:25 -0700)
References:  <20120911213804.GA9817@ethic.thought.org> <20120912011443.5df17cf2.freebsd@edvax.de> <20120912002408.GA10496@ethic.thought.org> <20120912011725.GG3066@hs1.VERBENA>

next in thread | previous in thread | raw e-mail | index | archive | help
>> On Tue, 11 Sep 2012 14:38:04 -0700, Gary Kline wrote:

G> I'm trying to checksum directories as I move them around.  ive read the
G> man page for sum and cksum ... or maybe skimmed them.  no joy.  anybody
G> know of a utility to do this?  I've got files that are decades old...

   I wouldn't use CRC32 to check file integrity; use SHA1 or MD5 at the
   very least.  See http://home.comcast.net/~bretm/hash/8.html for details.

>> On Tue, 11 Sep 2012 18:17:25 -0700, 
>> Colin Barnabas <colin.barnabas@gmail.com> replied:

   Are you by any chance a "Dark Shadows" fan?

C> This works for me:
C> $ find foo/ -type f -print0 | xargs -0 md5 >> foo.md5

   I do something similar when copying files to a backup server; it's not
   unheard of for SSH to drop a session or a drive to have a bad spot.

   An easy-to-automate way is: get a list of files, use the hash of your
   choice to generate signatures, sort the signature file by the hash, and
   then get the hash value of the signature file.  Here's an example using
   my bin directory:

     me% ls
     aline       dir         hist        makecfg     mx          ro
     authlog     diskused    isodate     makekey     mylook      setperm
     avg         dline       kernlog     makepass    n32         sha
     buildenv    dnslog      lastdom     mb          n64         sshlog
     cline       dosrc       linkdups    md5path     nr          sulog
     cmdlog      dot         ll          memuse      ntplog      syslog
     conlog      dp          lsl         mgrep       pathinfo    tc
     core        f           lslm        mk          ping        tcv
     cronlog     fixhist     lsn         mkdtree     plog        tl
     daemonlog   fmt         lsnm        mkproto     pwgen       tr0
     dblog       getperm     lss         mkrcs       r           tx
     dbrun       google      lssm        mongolog    rand        vi
     dh          haval       lst         month       range       zp
     dig         help2man    lstm        mv2inode
     
     me% find . -type f -print0 | xargs -0 md5 -r | sort > /tmp/dir.md5
     
     me% cat /tmp/dir.md5
     01328aeb4fd0eb3d998f4d7ad407a73f ./setperm
     017d6d622fb93bf7f23c0fb7b96b16eb ./core
     0287839688bd660676582266685b05bd ./mkrcs
     0b97494883c76da546e3603d1b65e7b2 ./pwgen
     ...
     ddbed53e795724e4a6683e7b0987284c ./authlog
     ddbed53e795724e4a6683e7b0987284c ./cmdlog
     ddbed53e795724e4a6683e7b0987284c ./conlog
     ddbed53e795724e4a6683e7b0987284c ./cronlog
     ddbed53e795724e4a6683e7b0987284c ./daemonlog
     ddbed53e795724e4a6683e7b0987284c ./kernlog
     ddbed53e795724e4a6683e7b0987284c ./ntplog
     ddbed53e795724e4a6683e7b0987284c ./sulog
     ddbed53e795724e4a6683e7b0987284c ./syslog
     ...
     fdff1fd84d47f76dbd4954c607d66714 ./dbrun
     ff5e24efec5cf1e17cf32c58e9c4b317 ./tr0

   The *log files are hard-linked, hence the duplicate MD5 values.
     
     me% md5 -r /tmp/dir.md5
     fdc34a5a5df7807d4fc45739d2d3039f /tmp/dir.md5

   If I copy these files elsewhere, I can repeat the steps and just compare
   the final hash; if it's anything other than 'fdc34...3039f', something's
   wrong.

-- 
Karl Vogel                      I don't speak for the USAF or my company

When In Doubt, Empty The Magazine    --bumper-sticker seen on military base



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20120912181105.77E05BEA6>