How to Use md5sum Command?

11

We have already discussed in another tutorial about the Linux sha1sum command to check the file’s integrity. Similarly, on Linux systems, there are multiple checksums for the verification of messages, files, and data integrity.

It is good to verify the operations when performed, like if you’re installing anything from the website, then to verify if it is installed correctly, there must be some checksums.

A popular tool among Linux users is “md5sum” which comes from “MD5” known as the message-digest algorithm. The Md5 consists of a 128-bit cryptographic hash value that is used for the authentication of files and data integrity.

The “md5sum” checksum is a well-suited tool that helps calculate and verify the 128-bit hashes. It is a built-in program in most of the UNIX systems to compute and generate input files for a 128-bit message digest.

The syntax of the “md5sum” command is:

md5sum [option…] [file]

The “md5sum” Command Options

The options of the “md5sum” command are mentioned in the given table:

Option Description
-b Used for binary mode
-c Used to read MD5 files and check
-tag Used to create BSD style checksum
-t Used for text mode
-ignore-missing To ignore report message for the missing files
-quiet To stop the “ok” message for every successful file
-status To stop displaying output all the time.
-strict Used for improperly formatted checksums
-warn Displays warning message about improperly formatted checksums

How to Use md5sum Command Options?

Let’s do and use some examples to understand the working of the “md5sum” command with options:

Create a text file and write random text in it. Suppose, create a file named “test_file1” and add the following content to it:

Now, execute the following md5sum command to verify the file:

How to Use md5sum Command? 1620439561 17 How to Use md5sum Command

Print the generated output in the BSD-style format using the “–tag” option:

$ md5sum –tag test_file1.txt

How to Use md5sum Command? 1620439561 6 How to Use md5sum Command

You can also check the integrity of any other format file. For instance, make a .cpp file and name it “test_file2.cpp” and write any program and save it.

How to Use md5sum Command? 1620439561 910 How to Use md5sum Command

Execute the given command to verify the .cpp file:

How to Use md5sum Command? 1620439562 835 How to Use md5sum Command

Store the value of MD5 in a file and verify it. For this, use mentioned command in the following way to move the value in the MD5 algorithm:

$ md5sum test_file2.cpp > testmd5.md5

How to Use md5sum Command? 1620439562 212 How to Use md5sum Command

The above command will move the value in testmd5.md5 file.

NOTE: The testmd5.md5 is a random name I created, you can change the name according to your choice. Once you run this command, a file will be created in the directory with the mentioned name.

Execute the “-c” option with the md5sum command to check the file’s content:

$ md5sum –c testmd5.md5

How to Use md5sum Command? 1620439563 750 How to Use md5sum Command

Similarly, you can also move the standard output of multiple files in the testmd5.md5 to verify the content:

$ md5sum test_file1.txt test_file2.cpp > testmd5.md5

How to Use md5sum Command? 1620439563 731 How to Use md5sum Command

Add some other content in the test_file1 to verify if the MD5 checksum gives the error message. For this, add content in the “test_file1.txt” using “echo”:

$ echo “Hello Linux Writers” >> test_file1.txt

How to Use md5sum Command? 1620439564 900 How to Use md5sum Command

The above command will append “Hello Linux Writers” in the text file.

Now, run the “–check” option to check what output will generate in the terminal after changes have been made:

$ md5sum –check testmd5.md5

How to Use md5sum Command? 1620439564 281 How to Use md5sum Command

The generated output indicates that the content of the files doesn’t match.

Use the “–quiet” option to not print the “Ok” message for successfully verified files. It will print the failure result only:

$ md5sum –quiet –check testmd5.md5

How to Use md5sum Command? 1620439565 30 How to Use md5sum Command

Run the “–warn” option to display a message if checksums files are improperly formatted. It will generate a warning message in the terminal:

$ md5sum -c –warn testmd5.md5

How to Use md5sum Command? 1620439565 610 How to Use md5sum Command

Conclusion:

In this guide, we have discussed the “md5sum” command tool that is used to check the 128-bit hashes. We have also checked the data integrity of different files using the “md5sum” command options.

This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish. Accept Read More