Linux command explanation: md5sum command

Source: Internet
Author: User

Objective

In the network transmission, transfer between devices, copying large files, etc., may occur before and after the transmission of data inconsistencies. This is likely to occur in a relatively unstable environment such as the network. Then verifying the integrity of the file is also imperative.

Instructions for use

The md5sum command is used to generate and verify the MD5 value of the file. It checks the contents of the file bit by bits. Is the content of the file, regardless of the file name, which is the same as the MD5 value. The MD5 value is a 128-bit binary data that is converted to a 16 binary that is the binary value of the 32 (128/4) bit.

MD5 checksum, there is a small probability that different files generated by MD5 may be the same. A more secure check algorithm than MD5 is also available in the Sha* series.

In the network transmission, we verify the source file to obtain its md5sum, after the transfer is complete, verify its target file, and compare if the source and destination files MD5 consistent, it means that the file transfer no exception. Otherwise the description file is not transmitted correctly during transmission.

Important options:

-B reads the contents of the file into binary mode

-T reads the contents of the file into text mode

-C verifies an existing file based on the generated MD5 value

After the--status check is complete, the error or the correct prompt message is not generated and can be judged by the return value of the command.

Examples of Use
Makefile MD5 value

Md5sum file

  1: [[email protected] lianxi]# md5sum data  
  2:0a6de444981b68d6a049053296491e49 data  
use pass to pair multiple files for MD5
  1: [[email protected] lianxi]# md5sum *  
 
    
      2:0a6de444981b68d6a049053296491e49 data  
    
  3:13df384c47dd2638fd923 F60c40224c6 data2  
md5sum verifies the contents of the file, as is the case with the file name,

Same as the MD5 of the same content. I copy the file first, and then md5,md5 the same value for a file that does not have the same name

  1: [[email protected] lianxi]# CP data data.bak< /span> 
  2: [[email protected] lianxi]# ls  
  3:da Ta data.bak  
  4: [[email protected] lianxi]# md5sum *  
  5:0a6de444981b68d6a049053296491e49 data  
  6:0a6de444981b68d6a0490532 96491e49 Data.bak  
to read and verify files in text or binary mode

-B reads content in binary mode

-T reads the contents of the file in text mode check

Although it is a different read-in mode, it is the same when you are seeking MD5. Because it is a bit-wise check.

The following text file, regardless of which mode reads MD5, is consistent.

  1: [[email protected] lianxi]# file data  
  2:dat A:ascii text  
  3: [[email protected] lianxi]# md5sum data  
  4:0a6de444981b68d6a049053296491e49 data  
  5: [[Email protect 
 ED] lianxi]# md5sum-b data  
  6:0a6de444981b68d6a049053296491e49 *data  
  7: [[email protected] lianxi]# md5sum-t data  
  8:0a6de444981b68d6a049053296491e49 data  
MD5 value redirection

Redirects the generated MD5 value to the specified file, usually with a file extension that we would have ordered. MD5

  1: [[email protected] Lia nxi]# md5sum data > Data.md5  
  2: [[email protected] lianxi]# md5sum data 
  3:0a6de444981b68d6a049053296491e49 data  
  4: [[ Email protected] lianxi]# cat data.md5  
  5:0a6de444981b68d6a049053296491e49 D ATA  
redirect MD5 of multiple files to the specified file

MD5 each file as a single line

  1: [[email protected] lianxi]# ls 
  2:data data.bak data.md5 d.md5  
  3: [[email& Nbsp;protected] lianxi]# md5sum data* > D.md5  
  4: [[email protected] Lianxi] # cat D.md5  
  5:0a6de444981b68d6a049053296491e49 data  
  6:0a6de444981b68d6a049053296491e49 data.bak  
  7:0bd94658869c53cdcdf35a0 F7DE93E01 data.md5  
redirect Append

New file ls is added here, MD5 it separately, append its MD5 to the file

  1: [[email protected] lianxi]# 
     
      cp/bin/ls. 
       
  2: [[email protected] lianxi]# ls  
  3:data data.bak data.md5 d.md5 ls  
  4: [[email protected] lianxi]# md5sum ls >> d.md5  
  5: [[email protected] lianxi]# cat d.md5  
  6:0a6de444981b68d6a049053296491e49 data  
  7:0a6de444981b68d6a049053296491e49 data.bak  
  8:0bd94658869c53cdcdf35a0f7de93e01 data.md5  
  9: c6337b20f3c159544bff5cf622391f9e ls   
MD5 check

-C option to verify the file MD5. Checksum, the checksum is based on the generated MD5. Generates the MD5 of the current file and compares it to the previously generated MD5, returns OK if it is consistent, or returns an error message

Md5sum–c D.MD5

   
   2:data:ok
   3:data.bak:ok
   4:data.md5:ok
   5:ls:ok

File MD5 changes after you modify the file

   1: [[email protected] lianxi]# ls
   2:data
   
   2360752c3368ca4f89169f5ecc06e383  Data
   5: [[email protected] lianxi]# md5sum data  > DATA.MD5
   6: [[email protected] lianxi]# echo "LWG" >> data
   7: [[email protected] lianxi]# md5sum data
   287d237083a42f09785daa46a5fa3afe  Data
   
  10:data:failed
  Md5sum:warning:1 of 1 computed checksum did not match
--status, does not display the checksum information, the command returns the value to judge

Checksum return 0, inconsistent return 1

   
   2:data:failed
   3:md5sum:warning:1 of 1 computed checksum did not match
   
   5: [[email protected] lianxi]# echo $?
   6:1
Multiple file file checksums with grep

Filter out the right information with grep

   
   2:acpid:ok
   3:acpid.1:ok
   4:anaconda.log:ok
   5:anaconda.syslog:ok
   6:anaconda.xlog:ok
   7:boot.log:ok
   8:boot.log.1:ok
   9: ...
  10: ...
  11: Omit Middle part
  12: ...
  13: ...
  14:yum.log.2:ok
  15:md5sum:warning:1 of computed checksums did not match
   1: [[email protected] lianxi]# md5sum-c. /VALUE.MD5 | Grep-v OK  
   2:md5sum:warning:1 of computed checksums did not match
   3:cron.1:failed
Special Instructions

1) md5sum is verifying the contents of the file, regardless of the same file name

2) The Md5sum value is bit-wise, so the larger the file, the longer the check time.

Summarize

Verify the generated file checksum by md5sum, to discover the inconsistency of file content caused by file transfer (network transmission, replication, transmission between different devices in the local).

Linux command explanation: md5sum command

Related Article

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.