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:
The “md5sum” Command Options
The options of the “md5sum” command are mentioned in the given table:
|-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:
Print the generated output in the BSD-style format using the “–tag” option:
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.
Execute the given command to verify the .cpp file:
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:
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:
Similarly, you can also move the standard output of multiple files in the testmd5.md5 to verify the content:
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”:
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:
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:
Run the “–warn” option to display a message if checksums files are improperly formatted. It will generate a warning message in the terminal:
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.