Misc Code : Miscellaneous code that I write
Updated: 2/24/2003; 5:50:44 PM.

 

Subscribe to "Misc Code" in Radio UserLand.

Click to see the XML version of this web page.

Click here to send an email to the editor of this weblog.

 
 

Monday, January 06, 2003

Here's a bash script that I wrote to calculate the MD5 hash of all files in the specified directory and below.  It's quick and dirty, but I've found it useful to compare files in 2 directories to see if anything has changed.  I can pipe the results out to a file for each directory and then diff them.  OR, even better, you can compare them with md5sum itself by:

cd <dir-to-compare>
md5sum -c <file-contatining-sums>

Here's the script:

#!/bin/bash
# Script that calculates an MD5 hash for each file in the specified directory
# and all directories below that.
#
# Author: Tom Pierce
# Date: 10/31/02

export IFS=$'t\n'

# a quick check to see if any files were given
# if none then its better not to do anything than rename some non-existent
# files!!
if [ "$1" == "" ]
then
echo "Usage: md5dir "
exit 0
fi

# For each file in the specified directory, get the md5
for file in $(find $1 -type f)
do
md5sum "$file"
done


10:34:31 AM    

© Copyright 2003 Tom Pierce.



Click here to visit the Radio UserLand website.

 


January 2003
Sun Mon Tue Wed Thu Fri Sat
      1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31  
Dec   Feb