0

I am running a script that copy a file from one location to other. In script I am calculating MD5sum using below command of original file and copied file and they are different:

echo -n "file" | md5sum

How come a same file have different MD5sum? Does copy command change something in Linux? I have also checked checksum using cksum filename and it is also coming different.

1
  • 5
    echo -n "file" | md5sum calculates the sum of the string "file", you want cat file | md5sum or just md5sum file
    – Zelda
    Jan 30, 2014 at 12:37

2 Answers 2

6
echo -n "file" | md5sum

You are not calculating the checksum of the file, but of the filename. It is probably different because you are using two different paths (echo -n "/old/path/to/file" | md5sum vs. echo -n "/new/path/to/file" | md5sum).

To calculate the md5sum of the file, use this command:

md5sum file
2
  • Thanks Martin.I have one more confusion that if a file is zipped into tgz then untar it. Then the both original and untar file will also have the same checksum or different?
    – Infotechie
    Jan 30, 2014 at 12:34
  • If you compare the original file with the zipped tgz file - no, they will not have the same checksum. If you extract the tgz file and compare the extracted file with the original file - yes, they must have the same checksum. Jan 30, 2014 at 12:37
0

You can also use http://sourceforge.net/projects/crcsum/?source=directory which provides a cp and mv extended with checksum calculation & verification

1
  • Whilst this may theoretically answer the question, it would be preferable to include the essential parts of the answer here, and provide the link for reference.
    – slm
    Oct 21, 2014 at 13:47

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .