The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Operating Systems > Linux
.
google unix.com



Linux RedHat, Ubuntu, SUSE, Fedora, Debian, Mandriva, Slackware, Gentoo linux, PCLinuxOS. All Linux questions here!

Reply
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 4 Weeks Ago
greenja greenja is offline
Registered User
  
 

Join Date: Oct 2009
Posts: 6
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?

  #2 (permalink)  
Old 4 Weeks Ago
pludi's Avatar
pludi pludi is offline Forum Staff  
Moderator
  
 

Join Date: Dec 2008
Location: .at
Posts: 1,843
The md5sum command doesn't work across the network. You'll have to use other commands to pipe into it, eg:
Code:
ssh -l user Host_A 'cat /path/to/test01.tar.gz' | md5sum
or, to save bandwith:
Code:
ssh -l user Host_A 'md5sum /path/to/test01.tar.gz'
Analog use for Host_B
  #3 (permalink)  
Old 4 Weeks Ago
greenja greenja is offline
Registered User
  
 

Join Date: Oct 2009
Posts: 6
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
  #4 (permalink)  
Old 4 Weeks Ago
pludi's Avatar
pludi pludi is offline Forum Staff  
Moderator
  
 

Join Date: Dec 2008
Location: .at
Posts: 1,843
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
Code:
51e3f4849cf415dbc9abdb46412df72e  -
Capture the first part in a variable (either through cut or awk). Do that for both files, and compare (eg with if)
Code:
if [ "$SUM1" = "$SUM2" ]
  #5 (permalink)  
Old 4 Weeks Ago
greenja greenja is offline
Registered User
  
 

Join Date: Oct 2009
Posts: 6
thank you again! I will try to do that.
  #6 (permalink)  
Old 4 Weeks Ago
binlib binlib is offline
Registered User
  
 

Join Date: Aug 2009
Location: New Jersey
Posts: 56
Code:
md5sum test01.tar.gz |ssh remote md5sum -c
If they are located in different directories, do
Code:
(cd /path/to/local/file;md5sum test01.tar.gz) |ssh remote 'cd /path/to/remote/file;md5sum -c'
  #7 (permalink)  
Old 4 Weeks Ago
greenja greenja is offline
Registered User
  
 

Join Date: Oct 2009
Posts: 6
binlib
Thank you!

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

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 07:41 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0