title: Shell Script for comparing two folders
body: <p>I want to write a shell script to compare two folders and save the difference in a different folder. </p>
  
  <p>Suppose FolderA has five sub folders as A1,A2,A3,A4,A5 and FolderB has five sub folders as A1,A2,A3,A4,A5. Both folders A &amp; B are same in structure but the files inside folders A1,A2 and so on have some differences.</p>
  
  <p>I want to compare the difference of the files in FolderA-> A1 with FolderB-> A1 and save the result in a folder Difference/A1. I tried to write the script but it's not working — please guide me?</p>
  
  <pre><code>    #!/bin/bash
      # setup folders for our different stages
      DIST=/app/webmcore1/Demo/FolderA
      DIST_OLD=/app/webmcore1/Demo/FolderB
      mkdir -p Difference/newAddition
      mkdir -p Difference/DifferenceIs
      DIST_UPGRADE=/app/webmcore1/Demo/Difference
      cd $DIST
      find . -type f | while read filename
      do
          if [ ! -f "$DIST_OLD$filename" ]; then
          cp --parents "$filename" $DIST_UPGRADE/newAddition
          continue
          fi
          diff "$filename" "$DIST_OLD$filename" &gt; /app/webmcore1/Demo/DIST_UPGRADE/DifferenceIs
      done
  </code></pre>