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.

  1. #!/bin/sh
  2.  
  3. # Get a list of files in a directory without the .md5 extension
  4. # Note the ticks
  5. LIST=`find . -name "*.txt" -a ! -name '.md5'`
  6.  
  7. # For each file in the list, generate an MD5sum and
  8. # the place the sum inside of a file of the same name, but with
  9. # the extension.md5
  10. for FILE in $LIST;
  11. do
  12.   md5sum $FILE >> FILE.md5
  13. done
  14.  
  15. 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>
  • 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.