Windows and Linux judge whether two files are the same according to the md5 value of the file

MD5 (Message-Digest Algorithm 5) is a common hash function that takes a message of any length as input and outputs a fixed-length message digest (usually 128 bits), which is the so-called MD5 value. MD5 values ​​are often used to verify the integrity of data and to compare the contents of two files for the same.

Specifically, if the MD5 values ​​of two files are the same, their contents can be considered to be the same, because even a slight change in the contents of the files will cause their MD5 values ​​to be completely different. Therefore, the MD5 value can be used to verify the integrity of the file. For example, when downloading a file, the MD5 value of the file can be calculated and compared with the MD5 value provided by the publisher to ensure that the file has not been tampered with or damaged.

In both Linux and Windows operating systems, there are command-line tools for calculating the MD5 value of files, but the command syntax is slightly different.

Linux

The md5sum command in the Linux system can calculate the MD5 value of a file, and its basic syntax is as follows:

md5sum 文件名

For example, to calculate the MD5 value of the file example.txt, you can execute the following command:

md5sum example.txt

insert image description here

Windows

There is no native md5 command in the Windows system, but you can use third-party tools, such as the certutil command officially provided by Microsoft and the open source tool CertUtil.exe, whose basic syntax is as follows:

certutil -hashfile 文件名 MD5

For example, to calculate the MD5 value of the file example.txt, you can execute the following command:

certutil -hashfile example.txt MD5
insert image description here

Guess you like

Origin blog.csdn.net/QH2107/article/details/130999790