Shell learns 48 days----file checksum match

Source: Internet
Author: User

File Checksum Matching

If you suspect that there may be many files with the same Nevin , instead of comparing all ranks comparisons with cmp or diff , The amount of time that is spent will increase as the number of files increases to the sub-party .

This is possible with file checksum ( achieve approximately linear performance Span style= "Font-family:times New Roman". There are many tools available to calculate the checksum of a file and a string includes 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 can verify the original file and the received file .

By comparing the results of both checks , It is possible to verify that the received file is correct . 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

You can follow the following method to permanently vera the file when data integrity :

$MD 5sum-c F1.MD5

F1: OK

Analysis : If a determination is present , The document is undamaged .

Shalsum is another common test algorithm . he generates a length from the given input file + hexadecimal string of characters . its usage and md5sum very similar .

Multiple files can be verified

&md5sum F1 F2 > File.md5

$cat FILE.MD5

42A6AB275D6AE3A62AB448FB44DFFB8A F1

42a6ab275d6ae3a62ab448fb44dffb8a F2

Parse : The output will contain an inspection result string for a single file in each row .

You can verify data integrity with the 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

Verifying a directory

Validating a directory means that we need to evaluate all the files in the directory recursively .

He can use command md5deep or shaldeep to achieve . First , need to install Md5deep package ensures that these commands can be found . Use 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

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

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.