Cyberithub

10 Popular Unix/Linux md5sum command examples to validate checksum

Advertisements

In this article, I will take you through 10 Popular Unix/Linux md5sum command examples to validate checksum. You might have faced a situation where some file which was working fine in source location when you transfer it to some other location are not working anymore. This might happen due to some change in File during transit from Source to Destination. This can be easily verified by using a Linux/Unix md5sum command. You can verify the checksum value of the File in source and destination location which will confirm the Integrity of the File. I will explain the Usage of this tool through various examples in below sections.

SYNOPSIS

md5sum [OPTION]... [FILE]...

Advertisements

10 Popular Unix/Linux md5sum command examples to validate checksum

md5sum command examples to validate checksum

Also Read: 17 Useful Linux chown command examples to change owner and group

Example 1: How to Check md5sum command version

If you want to check md5sum command version then you need to use md5sum --version command as shown below. As you can see from the output, current md5sum version is 8.22.

Advertisements
[root@localhost ~]# md5sum --version
md5sum (GNU coreutils) 8.22
Copyright (C) 2013 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>.
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

Written by Ulrich Drepper, Scott Miller, and David Madore.

NOTE:

Please note that here I am using root user to run all the below commands.You can use any user with sudo access to run all these commands. For more information Please check Step by Step: How to Add User to Sudoers to provide sudo access to the User.

Example 2: How to see the Checksum of a File using md5sum command

If you want to see the checksum value of a file then you need to use below md5sum command. In this example, we are checking the checksum value of CentOS.ISO image file using md5sum CentOS.ISO command.

Advertisements
[root@localhost ~]# md5sum CentOS.ISO
143b736c32948ac4a5b1aa2fff2dcc0c CentOS.ISO

Example 3: How to View the Checksum Value of a File in Text Mode

If you want to view the checksum value of a File in text mode then you need to use -t option with md5sum command as shown below. In this example, we are checking the checksum value of CentOS.ISO image in text mode using md5sum -t CentOS.ISO command.

[root@localhost ~]# md5sum -t CentOS.ISO
143b736c32948ac4a5b1aa2fff2dcc0c CentOS.ISO

-t : read in text mode (default). More on md5sum command Man Page.

Advertisements

Example 4: How to Show the Checksum Value of a File in Binary Mode

If you want to show the checksum value of a file in binary mode then you need to use -b option with md5sum command as shown below. In this example, we are checking the checksum value of CentOS.ISO Image in binary mode using md5sum -b CentOS.ISO command.

[root@localhost ~]# md5sum -b CentOS.ISO
143b736c32948ac4a5b1aa2fff2dcc0c *CentOS.ISO

-b : read in binary mode. More on md5sum command Man Page.

Example 5 : How to Verify Checksum of a File in Linux using md5sum command

If you want to verify the checksum of a file then you need to first save the MD5 checksum value in a file and then verify it using -c option as shown below. Here we are saving the MD5 checksum value of CentOS.ISO image in a Imagemd5 file using md5sum -t CentOS.ISO >> Imagemd5 command and then we are verifying it using md5sum -c Imagemd5 command.

[root@localhost ~]# md5sum -t CentOS.ISO >> Imagemd5
[root@localhost ~]# md5sum -c Imagemd5
CentOS.ISO: OK

-c : read MD5 sums from the FILEs and check them. More on md5sum command Man Page.

Example 6: How to Show Improperly Formatted Lines using md5sum command

If you want to show the improperly formatted lines while verifying the checksum value then you need to use --strict option with -c option as shown below. As you can see from the output the checksum value of CentOS.ISO image which was saved in Imagemd5 file is not proper and hence it is failing.

[root@localhost ~]# md5sum -c --strict Imagemd5
CentOS.ISO: FAILED
md5sum: WARNING: 1 computed checksum did NOT match

--strict : exit non-zero for improperly formatted checksum lines. More on md5sum command Man Page.

Example 7: How to Create BSD Style Checksum 

If you want to create BSD Style Checksum then you need to use --tag option with md5sum command as shown below. In this example, we are creating checksum for Imagemd5 using md5sum --tag Imagemd5 command.

[root@localhost ~]# md5sum --tag Imagemd5
MD5 (Imagemd5) = ae3e28ce74010b4992ffc502936457ec

--tag : create a BSD-style checksum. More on md5sum command Man Page.

Example 8: How to Verify Checksum of Multiple Files using md5sum command

If you want to verify the checksum value of multiple files simultaneously then you need to save all checksum values in a file and then verify using that file. In this example, we have CentOS.ISO, hello.txt and example.txt files whose checksum value we are saving in another multipleMD5 file using md5sum -t CentOS.ISO hello.txt example.txt >> multipleMD5 command. Then we are verifying this checksum value using md5sum -c multipleMD5 command.

[root@localhost ~]# md5sum -t CentOS.ISO hello.txt example.txt >> multipleMD5
[root@localhost ~]# md5sum -c multipleMD5
CentOS.ISO: OK
hello.txt: OK
example.txt: OK

Example 9: How to Check all available options of md5sum command

If you want to check all the available options of md5sum command then you need to use md5sum --help command as shown below.

[root@localhost ~]# md5sum --help
Usage: md5sum [OPTION]... [FILE]...
Print or check MD5 (128-bit) checksums.
With no FILE, or when FILE is -, read standard input.

-b, --binary read in binary mode
-c, --check read MD5 sums from the FILEs and check them
--tag create a BSD-style checksum
-t, --text read in text mode (default)
Note: There is no difference between binary and text mode option on GNU system.

The following four options are useful only when verifying checksums:
--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 lines
-w, --warn warn about improperly formatted checksum lines

--help display this help and exit
--version output version information and exit

The sums are computed as described in RFC 1321. When checking, the input
should be a former output of this program. The default mode is to print
a line with checksum, a character indicating input mode ('*' for binary,
space for text), and name for each FILE.

GNU coreutils online help: <http://www.gnu.org/software/coreutils/>
For complete documentation, run: info coreutils 'md5sum invocation'

Example 10: How to Check Man Page of md5sum command

If you want to check the Man Page of md5sum command then you need to use man md5sum command as shown below.

[root@localhost ~]# man md5sum
MD5SUM(1) User Commands MD5SUM(1)

NAME
md5sum - compute and check MD5 message digest

SYNOPSIS
md5sum [OPTION]... [FILE]...

DESCRIPTION
Print or check MD5 (128-bit) checksums. With no FILE, or when FILE is -, read standard input.

-b, --binary
read in binary mode

-c, --check
read MD5 sums from the FILEs and check them

--tag create a BSD-style checksum

-t, --text
read in text mode (default)

 

 

 

 

 

 

Popular Recommendations:-

5 Best Methods to Extract .gz File in Linux using gunzip, gzip and tar tool

12 Popular Unix/Linux uname command examples(How to Get Kernel Version)

How to Transfer Files to AWS EC2 Instance Using WinSCP in 3 Easy Steps

6 Easy Steps to Install Sendmail command in Linux (RHEL/CentOS 7/8)

Learn HTML Tables(v5) with Best Examples

Easy Steps to Install GCC(C and C++ Compiler) on CentOS 7

C# data types with Best Examples (.NET v4.7)

How to Transfer Files to an AWS EC2 Instance Using WinSCP in 3 Easy Steps

Leave a Comment