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 -->
  #6 (permalink)  
Old 06-22-2004
Ygor's Avatar
Ygor Ygor is offline Forum Staff  
Moderator
  
 

Join Date: Oct 2003
Location: -31.96,115.84
Posts: 1,409
Loop thru files in source directory; see if file exists in destination; if it does then see if the contents differ...
Code:
#!/usr/bin/ksh

SOURCE=/path/to/source/dir
DEST=/path/to/dest/dir
cd $SOURCE
for i in *
do
    if [ -f $DEST/$i ]
    then
        echo file $i exists
        if cmp -s $i $DEST/$i
        then
            echo files are the same
        else
            echo files are different
        fi
    else
        echo file $i does not exist
    fi
done