When downloading files from the internet especially from websites it often displays a hash value to make sure the download is completed correctly. The md5sum is a computer program that calculates and verifies 128-bit md5 hashes. This verifies data integrity using MD5(Message-Digest Algorithm 5).
In this article, I will discuss the usage of md5sum in Linux along with some examples.
Syntax of md5sum command in Linux
The syntax of how to use md5sum on a Linux system is given below.
md5sum [OPTION]... [FILE]..
You can use the following options with the md5sum command –
-b – Read in binary mode
-c – Read MD5 from files and check them
–tag – Create a BSD-style checksum
-t – Read in text mode(default)
-z – End each output line with NUL, not newline, and disable file name escaping
The following options are useful in verifying checksum –
--ignore-missing – Don’t report status for missing files
--quiet – Don’t print OK for each successfully verified file
--status – Don’t output anything, status code shows success
--strict – Exit non-zero for improperly formatted checksum files
--warn – Warn about improperly formatted checksum files
Usage of md5sum command in Linux
The following examples show the usage of the md5sum command in Linux.
Compute and display the hash value of a file
If you use the md5sum command without any options it will display the hash value and filename.
For example –
This will display :
You can use the
--tag option with the above command to display the output in BSD-style format.
Validating single or multiple files
You can use the md5sum command to validate multiple files in a single go. Store the hashes to a file later you can use it to verify whether any of the files have changed.
Here I will write hashes to file named hashfile and then we will validate that none of the files have changed.
md5sum testfile1.txt testfile2.txt testfile3.txt > hashfile
Now use the given command to validate the integrity of these files.
md5sum --check hashfile
You can see the output of this in the given image.
Now if you modify any of these files and then validate it the validation will be failed and you will get a warning. Here I made changes in the content of testfile1.txt so let’s validate the hashfile now.
md5sum --check hashfile
You will see the given output.
For more usage of this command in Linux, you can see the man page of this command in your terminal.
I hope now you understand how to use the md5sum command in Linux. Now if you have a query then write us in the comments below.