md5sum

Tool program for calculating and verifying file message digests

Supplementary instructions

md5sum command uses the MD5 message digest algorithm (128 bits) to calculate and check the checksum of the file. Generally speaking, after installing Linux, there will be the tool md5sum, which can be run directly in the command line terminal.

The MD5 algorithm is often used to verify the integrity of network file transmissions and prevent files from being tampered with. The full name of MD5 is Message-Digest Algorithm 5. This algorithm calculates information of any length bit by bit to generate a "fingerprint" (or fingerprint) with a binary length of 128 bits (hexadecimal length is 32 bits). (called "message digest"), the possibility that different files produce the same message digest is very, very small.

grammar

md5sum(options)(parameters)

Options

-b: Read files in binary mode;
-t or --text: Treat the input file as a text file;
-c: Read the MD5 checksum from the specified file and perform verification;
--status: No information is output when the verification is successful;
-w: Give a warning message when the verification is incorrect.

Parameters

File: Specify the text file that holds the file name and checksum.

Example

Use md5sum to generate password

Another way to get a random string that can be used as a password is to calculate an MD5 checksum! The checksum does look like a random string of strings put together that we can use as a password. Make sure your calculation source is a variable, so the checksum generated will be different each time you run the command. Such as date! The date command always produces different output.

[root@localhost ~]# date | md5sum
6a43f2c246cdc3e6a3592652f831d186 -

**Generate the md5 value of a file insert.sql: **

[root@localhost ~]# md5sum insert.sql
bcda6cb5c704664f989703ac5a88f112 insert.sql

Check whether the file testfile has been modified:

First generate the md5 file:

md5sum testfile > testfile.md5

examine:

md5sum testfile -c testfile.md5

If the file has not changed, the output should be as follows:

forsort: OK

At this time, the md5sum command returns 0.

If the file has changed, the output should look like this:

forsort: FAILED
md5sum: WARNING: 1 of 1 computed checksum did NOT match

At this time, the md5sum command returns non-0.

Here, the file name used for checking is arbitrary. If you don't want any output, use md5sum testfile --status -c testfile.md5. At this time, you can check the result by returning the value.

Options for outputting information if the detected file is illegal during detection:

md5sum -w -c testfile.md5

After output, the file exception output is similar to the following:

md5sum: testfile.md5: 1: improperly formatted MD5 checksum line
md5sum: testfile.md5: no properly formatted MD5 checksum lines found

Here, testfile.md5 only has one line of information, but I think an extra character was added to it, making it illegal. If the md5 file is normal, it will be the same whether -w is present or not.