Linux md5sum verify file integrity __linux

Source: Internet
Author: User
Tags md5

1. Introduction

MD5 algorithm is often used to verify the integrity of network file transmission, to prevent files from being tampered with. MD5 full name is the digest to the algorithm (Message-digest algorithm 5), this algorithm for arbitrary length of information in a bitwise calculation, resulting in a binary length of 128 digits (hexadecimal length is 32 bits) of the "fingerprint" (or "Digest to"), The possibility that different documents produce the same report digest is very, very small.
On Linux or UNIX, md5sum is the tool that is used to compute and validate the document digest. In general, the installation of Linux, there will be md5sum this tool, directly in the command line terminal to run directly.

2. Command Format

md5sum [OPTION] ... [FILE] ...

3. Command Options

-B or--binary: treat the input file as a binary file.
-T or--text: treat the entered file as a text file (default).
-C or--check: used to read MD5 information from a file to check the consistency of the file. (See info)
--status: This option is used in conjunction with a check, which does not output at check time, but rather indicates the result of the check based on the return value.
-W or--warn: When checking, check the input of the MD5 information and no illegal lines, if there is output the appropriate information.

4. Examples

(1) The MD5 value of a file is produced, as follows:

[Root@test patch]# md5sum p182 > Cc.txt

In this way, the production of file p182 MD5 checksum file Cc.txt, open Cc.txt can see the following:

[Root@test patch]# Cat Cc.txt
dd05e55e3aca2d39e49a1a7d1b3fd404 p182

(2) Check whether two files are the same, you can compare the MD5 value of two files

[Root@test patch]# md5sum p182 > Ee.txt
[Root@test patch]# Cat Ee.txt
0f0b000b096ac947d6067466cc60ffd0 p182

[Root@test patch]# md5sum p183 > Ff.txt
[Root@test patch]# Cat Ff.txt
dd05e55e3aca2d39e49a1a7d1b3fd404 p183

(3) To judge whether a file is modified by MD5

[Root@test patch]# md5sum p182 > Cc.txt
[Root@test patch]# Cat Cc.txt
0f0b000b096ac947d6067466cc60ffd0 p182


Modify the following p182 file:

[Root@test patch]# VI p182

Compared to the original MD5 results:
[Root@test patch]# md5sum p182-c cc.txt
Md5sum:p182:no properly formatted MD5 checksum lines
P182:failed
Md5sum:warning:1 of 1 computed checksum did not match


The results of the modified MD5 are as follows:

[Root@test patch]# md5sum p182 > Dd.txt
[Root@test patch]# Cat Dd.txt
521e87e3331e94a483aec6bf19039845 p182


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.