If you deal with text files and want to just see the differences, I would customize the diff output, as hek2mgl suggested. But if you want more control, for example to execute some commands after finding different files or you must compare binary files, you may utilize find
and cmp
.
Below is the sample, which you may customize:
#!/bin/bash
IFS_SAVE="$IFS"
IFS=$'\x0a'
for f in $(find dir1 -type f -printf "%f\n"); do {
f1="dir1/$f"
f2="dir2/$f"
cmp --quiet "$f1" "$f2"
check=$?
if [ $check -eq 0 ] ; then
echo -e "OK: $f"
elif [ $check -eq 1 ] ; then
echo -en "Mismatch FOUND in files: "
filesize1=$(stat --printf="%s" "$f1" )
filesize2=$(stat --printf="%s" "$f2" )
echo "$f1" size:"$filesize1" "$f2" size:"$filesize2" check:"$check"
#you may put diff ... or anything else here
else
echo "cannot compare files, probably $f2 is missing"
fi
} ; done
IFS="$IFS_SAVE"
Depending on your situation (if filenames do not contain spaces, there are no missing files, etc.) you may omit some parts - this was just tailored from a larger script.