how to compare a two files in unix server.

Hi Friends,

I have a requirement like i have two files in diffrent locations. i want to compare these two files, if both the files are same i want to return "0" else return 1.

Please help me on this.

Thanks
sreenu.

I'd recommend searching for a good book on basic UNIX commands. It's been so long since I had a UNIX class that I'm sure newer and better ones exist than when I was in school.

Try 'man diff' or Google for something like 'unix compare files'.

For something generic and simple like this, Google's probably a better choice than a forum like this. You'll get a lot more information much faster.

You could use the diff tool on that.
Please look at the diff man page.

Another solution may be to create checksums on the 2 files
with the md5sum binary, and afterwards compare the 2 checksums in your script.

diff <file1> <file2> &>/dev/null && echo 0 || echo 1
[ "$(md5sum <file1> 2>/dev/null | cut -d' ' -f1)" ==  "$(md5sum <file2> 2>/dev/null | cut -d' ' -f1)" ] && echo 0 || echo 1