This seems a lot better than creating a temporary file:
SIZE=`stat -c %s filea` cmp -s -n $SIZE filea fileb
Check the exit status to make sure that the first bytes of these files are really equal.
Update: as requested by xk0der, here is a longer example:
wormhole:tmp admp$ echo -n "fooa" > one # -n to supress newline wormhole:tmp admp$ echo -n "foobc" > two wormhole:tmp admp$ SIZE=`stat -c %s one` wormhole:tmp admp$ echo $SIZE 4 wormhole:tmp admp$ (cmp -s -n $SIZE one two && echo "equal") || echo "not equal" not equal wormhole:tmp admp$ echo -n "fooac" > two # first 4 bytes are equal now wormhole:tmp admp$ (cmp -s -n $SIZE one two && echo "equal") || echo "not equal" equal
In addition, on MacOS X you should use:
SIZE=`stat -f %z filename`
source share