title: Comparing two files based on md5 hash value
body: <p>I am using a find command to find files formatted 'DGT_????.JPG'. I am trying to get the script below to record the absolute paths of any file with the same name and the same hash from the source directory if it matches a file in target directory. I also want to enusure these files arent copied from source dirrectory to target directoyr. Then I want to record them into a new text file called 'dups.txt'. Can't seem to find a definite answer on the web so that's why I am posting this question. Thanks, fairly new to Linux.</p>
  
  <p>My code is below</p>
  
  <pre><code>#!/bin/sh
  clear
  SRC="$1"
  DEST="$2"
  
  if [ "$#" -eq 0 ]; then
      echo "two arguments required"
  fi
  
  if [ ! -d "$SRC" ]; then
      echo "Source directory does not found"
  
  fi
  
  
  if [ ! -d "$DEST" ]; then
      mkdir "$DEST"
  fi
  
  
  for image in $(find "$SRC" -type f -iname DGT_[0-9][0-9][0-9][0-9].JPG)
  do
      md5sum=$(md5sum &lt; "$image")        
      for duplicate in "$DEST"  
      do
          [ "$image" = "$duplicate" ] &amp;&amp; continue      
          [ "$md5sum" = "$(md5sum &lt; "$duplicate")" ] &gt;&gt; dups.txt  
      done
      cp --backup --suffix=.JPG     "$image" "$DEST"
  done
  </code></pre>