Bash Scripting - Recursive MD5sum On Files In Directory

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

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