Need Help: MD5

I am trying to compare two identical files by using md5 command, but cant get the right command parameters Please help me with any examples. All I want is to know how to compare two identical files which are residing on two different machines in my local network, for example:

Host_A - test01.tar.gz
Host_B - test01.tar.gz

Which command parameters should I use?

:frowning:

The md5sum command doesn't work across the network. You'll have to use other commands to pipe into it, eg:

ssh -l user Host_A 'cat /path/to/test01.tar.gz' | md5sum

or, to save bandwith:

ssh -l user Host_A 'md5sum /path/to/test01.tar.gz'

Analog use for Host_B

Pludi
Thank you!!! Ok, so now I know MD5 cant compare two identical files over the local network.Lets say: I will get the MD5 sum of two files, in this case what will be my next step? To use diff command?? I am a little bit confused here, it looks like its a simple problem, but it's not. I am Linux newbie :frowning:

The md5sum utility isn't meant to check if 2 files are the same, but if a file has been changed (small change in the file leads to big change in the hash). But that doesn't mean it can't be used for that, you'll just have to trick a bit.

The output of a typical md5sum run looks something like this

51e3f4849cf415dbc9abdb46412df72e  -

Capture the first part in a variable (either through cut or awk). Do that for both files, and compare (eg with if)

if [ "$SUM1" = "$SUM2" ]

thank you again! I will try to do that.

md5sum test01.tar.gz |ssh remote md5sum -c

If they are located in different directories, do

(cd /path/to/local/file;md5sum test01.tar.gz) |ssh remote 'cd /path/to/remote/file;md5sum -c'

binlib
Thank you!

md5sum test01.tar.gz |ssh remote md5sum -c
worked, finally! Now I can compare two identical files, right after the transfer!!! :slight_smile: