Bash Scripting - Recursive MD5sum On Files In Directory

Recently, I wanted to get the MD5sums of all of the files with a specific extension in the current directory and create a hash sum file for each. This was achieved using the following Bash script.

#!/bin/sh

# Get a list of files in a directory without the .md5 extension
# Note the ticks
LIST=`find . -name "*.txt" -a ! -name '.md5'`

# For each file in the list, generate an MD5sum and
# the place the sum inside of a file of the same name, but with
# the extension.md5
for FILE in $LIST;
do
  md5sum $FILE >> FILE.md5
done

exit 0

Blog tags: 

Add new comment

Filtered HTML

  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <blockquote> <code> <ul> <ol> <li> <dl> <dt> <dd> <python> <c>
  • Lines and paragraphs break automatically.

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.
By submitting this form, you accept the Mollom privacy policy.