Linux md5sum command - display or check the MD5 checksum

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:

Linux md5sum command

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.

Like(1)

Related

Linux Login Logout Command
Linux login commandLinux logout commandLinux nologin commandLinux exit commandLinux sulogin commandLinux rlogin commandLinux poweroff commandLinux ctrlaltdel CommandLinux shutdown commandLinux halt commandLinux reboot commandLinux init commandLinux runlevel commandLinux telinit command
Linux File Management Command
Linux cat commandLinux tac commandLinux nl commandLinux more commandLinux less commandLinux head commandLinux tail commandLinux rev commandLinux fold commandLinux fmt commandLinux expand commandLinux pr commandLinux sort commandLinux uniq commandLinux cut commandLinux comm commandLinux diff commandLinux join commandLinux diff3 commandLinux cmp commandLinux colrm commandLinux paste commandLinux mkdir commandLinux tr commandLinux split commandLinux csplit commandLinux tee commandLinux unexpand commandLinux patch commandLinux awk commandLinux sed commandLinux od commandLinux pwd commandLinux cd commandLinux ls commandLinux dir commandLinux dirs commandLinux touch commandLinux rmdir commandLinux cp commandLinux mv commandLinux rm commandLinux install commandLinux tmpwatch commandLinux file commandLinux du commandLinux wc commandLinux tree commandLinux cksum commandLinux md5sum commandLinux sum commandLinux dirname commandLinux mkfifo Command
Cron Expressions
Cron Expression to Run Every Day at 12 PMUnderstanding Vue Cron ExpressionsUnderstanding JS Cron ExpressionsA Comprehensive Guide to Cron Expressions for Scheduled TasksUnderstanding Linux Cron ExpressionsUnderstanding Quartz Cron ExpressionsCron ExpressionCron Time ExpressionCron Expression ParsingCron Expression: Executing a Task Every SecondCron Expression for Every Minute ExecutionCron Expression to Execute Every 10 MinutesCron Expression: Executing Every HourCron Expression to Execute Once a YearCron Expression: How to Schedule a Task to Run Daily at Midnight?