Shell learns 48 days----file checksum match

Source: Internet
Author: User

File Checksum Matching

If you suspect that there may be a lot of files with the same Nevin , rather than using cmp or diff to compare all ranks , cause the time it takes to grow as the number of files grows to a sub-party .

This is able to use file checksum ( achieve approximately linear performance Span style= "Font-family:times New Roman". There are very many tools available to calculate the checksum of a file and a string contains sum,cksum, checksum, message digest tool md5 md5sum, Security hashing algorithm tool sha,shalsum,sha256, sha384.

Case :

$echo-N "Hello" | md5sum | Cut-d '-f1

5d41402abc4b2a76b9719d911017c592

Parse : gets The MD5 of the string Hell .

md5sum: Show or check MD5 (128-bit) checksum , if no file option , or file is "-" is read from the standard input .

Echo-n: do not print line breaks

Cut:cut is used to cut columns or fields from a standard input or text file . Cut text to paste it into a text file .-D specify domain spaces and Tab key different field separators .-f1 represents the first domain .

The validator is used to generate a checksum key from the file and then use this check password to verify the integrity of the file . General documents can be distributed over the network with different locations . for a variety of reasons , data has the potential to lose several bits during the transfer process , resulting in file corruption .

So I need to use some test methods to determine if there are errors in the received file . we are able to verify the original file and the received file .

Verify that the received file is correct by comparing the results of both checks . validation is important for writing backup scripts or system maintenance scripts .

verify with md5sum or shalsum

The most well-known and most widely used tests and techniques are md5sum and shalsum. they use the response algorithm for file content to generate validation results .

In order to calculate md5sum, use the following command :

$MD 5sum F1

42A6AB275D6AE3A62AB448FB44DFFB8A F1

Analysis : The resulting result is a three-character hexadecimal string followed by a file name .

Redirect the output checksum to a file , and then use this MD5 file to verify the integrity of the data :

Md5sum f1>f1. MD5

The ability to follow the following methods to permanently Vera files when data integrity :

$MD 5sum-c F1.MD5

F1: OK

Analysis : Assuming that there is a determination , The document is lossless .

Shalsum is also a frequently used test algorithm . he generates a length from the given input file + hexadecimal string of characters . the method of use and md5sum very similar .

Ability to validate multiple files

&md5sum F1 F2 > File.md5

$cat FILE.MD5

42A6AB275D6AE3A62AB448FB44DFFB8A F1

42a6ab275d6ae3a62ab448fb44dffb8a F2

Parse : The output will include a test result string for a single file in each row .

Ability to verify data integrity with generated files in the following ways :

$MD 5sum-c FILE.MD5

F1: OK

F2: OK

Analysis : This command outputs a message that the check results match

To verify a folder

Verifying a folder means that we need to evaluate all the files in the folder recursively .

He can use command md5deep or shaldeep to achieve . First , need to install Md5deep The package ensures that these commands can be found . use methods such as the following :

$MD 5DEEP-RL DIRECTORY_PATH>DIRECTORY.MD5

Analysis : the-r option represents the use of a recursive method , and the-l ( lowercase letter l) uses relative paths . output absolute path by default .

Use the following command to verify :

$MD 5sum-c DIRCETORY.MD5

Shell learns 48 days----file checksum match

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.