The checksum (checksum) program is used to generate a test and secret key from a file and then use this checksum key to verify the integrity of the file.
The specific key used for file integrity testing is called checksums.
Checksums are important for writing backup scripts or system maintenance scripts.
1, the most well-known and most widely used calibration and technology is md5sum and SHA-1. They use the appropriate algorithm for file content to generate checksums.
2, in order to calculate the md5sum, use the following command:
$MD 5sum filename
68b329da9893e34099c7d8ad5cb9c940 filename
As shown above, Md5sum is a 32-character hexadecimal.
Redirect the checksum of the output to a file, and then use this MD5 file to verify the integrity of the data.
$MD 5sum filename >FILE_SUM.MD5
3. Working principle
The Md5sum checksum calculation method is as follows:
$MD 5sum file1 file2 file3.
When multiple files are used, the output contains a checksum for a single file in each row:
[CHECKNUM1] File1
[CHECKNUM1] File2
[CHECKNUM1] File3
Use the following method to verify data integrity with the generated file:
$MD 5sum-c FILE_SUM.MD5
#这个命令会输入校验和是否匹配的消息
If you need to use all the. MD5 information to check all the files, you can use the
$MD 5sum-c *.MD5
Similar to Md5sum, SHA-1 is another common checksum algorithm that corresponds to commands and files that are sha1sum and FILE_SUM.SHA1
4. Supplemental Content
Verifying multiple Files
Verifying a directory
The checksum is calculated from the file, and the checksum of the directory calculation means that we need to evaluate all the files in the directory in a recursive manner.
can be implemented with command Md5deep or Sha1deep. You first need to install the Md5deep package to ensure that you can find these commands. As follows
$MD 5deep-r1 directory_path > Directory.md5
#-r using recursive methods
#-1 uses relative paths. By default, Md5deep will output the absolute path of the file.
You can also calculate the checksum recursively by combining find
$find directory_path-type f-print0 |xargs-0 md5sum >>directory.md5
Use the following command to verify
$MD 5sum-c DIRECTORY.MD5
2.7 Checksum and verification