Sign up ×  I have a shell script in which I need to check if two
files are the same or not. I do this a for a lot of files, and
in my script this diffing seems to be the performance
bottleneck.  Here's the line:  diff -q $dst $new > /dev/null  if
($status) then ...  Could there be a faster way to compare the
files, maybe a custom algorithm instead of the default diff?
share|improve this question This is really nitpicking, but
you're not asking to see if two files are the same, you're
asking if two files have identical content. Same files have
identical inodes (and same device). –  Zano Nov 4 '14 at 9:08  4
Answers 4  up vote 56 down vote accepted  I believe cmp will
stop at the first byte difference:  cmp --silent $old $new ||
echo "files are different" share|improve this answer How can I
add more commands than only one? I want to copy a file and
roboot. –  Daniel Brunner Jun 14 '14 at 15:09 @DanielBrunner:
You can copy from the standard input to both a file and standard
output by using the tee command. – 