The Linux md5sum command is used to display or check the MD5 checksum.
Linux md5sum command Function Description
The md5sum command uses the MD5 message digest algorithm (128 bits) to calculate and check the checksum of a file. Generally, once Linux is installed, the tool md5sum is available and can be run directly from the command line terminal directly.
Use the md5sum command to display or check the MD5 (128-bit) checksum. The checksum will be generated according to the RFC 1321 specification. When checking, the input format given should be the same as the output sample format of the program. The default output mode outputs a line of checksum checksums with a character to indicate the file type ("*" for binary, " " for plain text) and also displays the name of each file.
Linux md5sum command Syntax
md5sum [Option] [File]
The meaning of each option in the command is shown in the table.
Option | Description |
---|---|
--quiet |
Output OK for files that are not verified successfully |
--status |
Do not output anything, use the exit status number to show success |
-w |
Warnings for inaccurately formatted checksum lines |
-t |
Read in plain text mode (default) |
-c |
Read the MD5 checksum from the file and check it |
-b |
Read in binary mode |
Linux md5sum command Examples
Display MD5 checksum of /home/deepinout/apidemos.com/ccc.txt file
md5sum /home/deepinout/apidemos.com/ccc.txt
Output:
Generate passwords using md5sum
Another way to get a random string that can be used as a password is to calculate the MD5 checksum! The checksums do look like random strings put together that we can use as passwords. Make sure that your calculation source is a variable, so that the checksum is generated differently each time you run the command. The date command will always generate a different output.
[root@localhost ~]# date | md5sum
6a43f2c246cdc3e6a3592652f831d186 -
Generate a file insert.sql with md5 values
[root@localhost ~]# md5sum insert.sql
bcda6cb5c704664f989703ac5a88f112 insert.sql
Check if the file testfile has been modified
First generate the md5 file –
md5sum testfile > testfile.md5
Check –
md5sum testfile -c testfile.md5
If there are no changes to the file, the output should be as follows –
forsort: OK
At this point, the md5sum command returns 0.
If the file has changed, the output should be as follows –
forsort: FAILED
md5sum: WARNING: 1 of 1 computed checksum did NOT match
In this case, the md5sum command returns non-zero.
Here, the file name used for the check is arbitrary. If you don’t want any output, then md5sum testfile --status -c testfile.md5
, and the result will be detected by the return value at this time.
The option to output information if the test file is illegal during testing –
md5sum -w -c testfile.md5
After the output, the file exception output looks 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 has only one line of information, but I think it has an extra character added to it, which makes it illegal. If the md5 file is normal then -w
is the same with or without it.