RE: MD5'ing a directory tree in Linux?

From: Chi, Allen (ChiA@nielsenmedia.com)
Date: 06/27/02


From: "Chi, Allen" <ChiA@nielsenmedia.com>
To: "'Josh Glover'" <jmglov@incogen.com>, "Mark G. Spencer" <mspencer@evidentdata.com>
Date: Thu, 27 Jun 2002 14:16:49 -0400


 find /dir -type f | xargs md5sum >> md5sums.list

-----Original Message-----
From: Josh Glover [mailto:jmglov@incogen.com]
Sent: Wednesday, June 26, 2002 11:38 PM
To: Mark G. Spencer
Cc: security-basics@securityfocus.com
Subject: Re: MD5'ing a directory tree in Linux?

Mark G. Spencer wrote:
> Is it possible to MD5 all the items in a directory tree using Linux? I
> am on a Redhat 7.3 workstation. I have read the man and info file for
> MD5SUM and also tried to run it against a directory without success. I
> get the error "Is a directory" which is very self explanatory.
>
> So .. Is there another MD5 utility with more flexibility? I basically
> need to MD5 every file individually in a large directory tree with the
> output redirected to a text file showing the path, filename, and hash of
> every file in that directory tree.

Oops... reading this more carefully, it sounds like you want to generate
the md5sums of all the files in the whole tree, not just a given
directory. In that case, you need a bit more firepower:

for i in `ls -R /dir | perl -e 'while(<STDIN>){if($_=~/(.+)\:$/){print
"$1\n";}}'`; do
        for j in $i/*; do
                md5sum $j >> md5sums.list
        done
done

Gross, but it will get the job done. Sorry for misunderstanding. ;)

-- 
Josh Glover <jmglov@incogen.com>

Associate Systems Administrator INCOGEN, Inc.