1. Introduction
The MD5 algorithm is often used to verify the integrity of network file transmission and prevent file tampering. The full name of MD5 is the Message Digest Algorithm (Message-Digest Algorithm 5). This Algorithm computes information of any length by bit, generate a "fingerprint" (or "Message Digest") with a binary length of 128 bits (32 bits in hexadecimal format "), different files may generate the same message digest.
In linux or Unix, md5sum is a tool program used to calculate and verify the file message digest. Generally, after Linux is installed, the md5sum tool runs directly on the command line terminal.
2. Command Format
Md5sum [OPTION]... [FILE]...
3. Command Options
-B or -- binary: treats the input file as a binary file.
-T or -- text: view the input file as a text file (default ).
-C or -- check: used to read md5 information from the file to check file consistency. (For more information, see info)
-- Status: This option is used with check. The check result is displayed based on the returned value instead of output during check.
-W or -- warn: check whether the input md5 information is invalid during check. If yes, the corresponding information is output.
4. Example
(1) generate the md5 value of a file as follows:
[Root @ bkjia www.bkjia.com] # md5sum p182> cc.txt
In this example, the md5check file cc.txt of p182is generated. Open cc.txt and you can see the following content:
[Root @ bkjia www.bkjia.com] # cat cc.txt
Dd05e55e3aca2d39e49a1a7d1b3fd404 p182
(2) check whether the two files are the same. You can compare the md5 values of the two files.
[Root @ bkjia www.bkjia.com] # md5sum p182> ee.txt
[Root @ bkjia www.bkjia.com] # cat ee.txt
0f0b000b096ac947d6067466cc60ffd0 p182
[Root @ bkjia www.bkjia.com] # md5sum p183> ff.txt
[Root @ bkjia www.bkjia.com] # cat ff.txt
Dd05e55e3aca2d39e49a1a7d1b3fd404 p183
(3) determine whether a file is modified and use md5 to determine
[Root @ bkjia www.bkjia.com] # md5sum p182> cc.txt
[Root @ bkjia www.bkjia.com] # cat cc.txt
0f0b000b096ac947d6067466cc60ffd0 p182
Modify the p182 file:
[Root @ bkjia www.bkjia.com] # vi p182
Compare with the original md5 result:
[Root @ bkjia www.bkjia.com] # md5sum p182-c cc.txt
Md5sum: p182: no properly formatted MD5 checksum lines found
P182: FAILED
Md5sum: WARNING: 1 of 1 computed checksum did NOT match
The md5 result after modification is as follows:
[Root @ bkjia www.bkjia.com] # md5sum p182> dd.txt
[Root @ bkjia www.bkjia.com] # cat dd.txt
521e87e3331e94a483aec6bf21339845 p182