The implementation algorithm of MD5 check for folder

Source: Internet
Author: User

Each copy of the same data (folder) can generate a unique MD5 checksum file, and we can determine whether the data is wrong by directly verifying the entire Data folder.

1. generate the MD5 Checksum file method for the entire folder :

Taking the Data folder as an example, we need to get the MD5 checksum value of the files in the entire Data folder, and we use the shell program to verify the files in the entire Data folder MD5.

Get the MD5 checksum file for the entire Data folder with the following command:

1 CD  data2find  ./  -type  f  -print0  |  Xargs  md5sum  >  data_temp.md53cat data_temp.md5 |  sort > Data.md5

(Locate each file in the data file and get the MD5 value of the file to be saved Data_temp.md5

, and then sort the MD5 value of the file to get the DATA.MD5 checksum file)

The data format in the Data.md5 file is as follows, the preceding string is the MD5 value of the file, followed by the path to the file relative to the Data folder. Because the MD5 value of each file is unique, the path to each file is different, so the MD5 file generated by the same folder is unique after sorting

040173e4c2c29787cd0e644bd3737f8f./preinstall/babaqunaer_1.3.6.apk

0054b51601427b2630793d43ed0b224c./pcvoice/7.mp3

2. generate MD5 checksum file program:

#!/bin/bash# author:huinatianyun# Updated Date: the-Geneva- -# Set Environment Variableslang=""Export lang# Here you have to set the locale, because sort sort is on each line of the file as a unit, compared to each other, the comparison principle is to compare from the first character backward, the language environment, the character encoding may be different, so it will result in inconsistent file sorting results, LANG=""indicates that the default setting is en_USEcho ""Echo ""Echo "Please put generate_md5_value.sh, Custdata.tar, Hpdata.tar, Hwapudata.tar in the same directory,"Echo ""Read-P"Is you put generate_md5_value.sh in the right position? (y/n):"Select_ynEcho ""Echo ""if["$select _yn"=="Y"] || ["$select _yn"=="y"]; ThenEcho "start generate Data.md5 ..."CD./DataFind./-type F-print0 |Xargs-0md5sum |Sort>.. /DATA.MD5 #XargsCommand0 is a null character as a delimiter, because some of the name of the directory is a space, and Xargs is the default is a space-delimited, it will mistakenly think that there are spaces in the directory path is two paths, replaced by null character is to eliminate the problemEcho "generate MD5 value over"elif["$select _yn"=="N"] || ["$select _yn"=="N"]; Then Echo "stop generate MD5 value!"ElseEcho "I don ' t know what your choice is!!!"fi 

3. Data check method:

Through the above method to the Data folder to generate a copy of the MD5 check file, this MD5 file can be used as the Data folder to verify the file, verify that a folder data is the same way as data is the same way for the folder to generate a copy of the MD5 checksum file, And then the same as the check file, if the two files are the same, it is considered that the two pairs of data folders consistent

The implementation algorithm of MD5 check for folder

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.