The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com




View Single Post in the UNIX and Linux Forums - Click on the Thread or Permalink to View Entire Thread -->
  #2 (permalink)  
Old 02-08-2007
jim mcnamara jim mcnamara is offline Forum Staff  
...@...
  
 

Join Date: Feb 2004
Location: NM
Posts: 5,808
You can use md5 or cksum to get a checksum for each file. Assuming you have identical filename, each directory has the same number of files in both directories and the directories are:
/path/to/source/dir1 and /path/to/source/dir2
try something like this (untested)


Code:
#!/bin/ksh
cd /path/to/source
mkdir ./both/dir1
mkdir ./both/dir2
cd .dir1
find . -type f | \
while read file1
do
     cksum $file1 | read ck1 dummy dummy1
     file2=../dir2/"$file"
     cksum $file2 | read ck2 dummy dummy1
     if [[ "$ck1" != "$ck2" ]] ; then
        cp $file1 ../both/dir1/$file1
        $( cd /path/to/source/dir2 ; cp $file1 ../both/dir2/$file1)
     fi
done