md5sum Command in Linux with Examples
Last Updated :
19 Jul, 2024
The md5sum is designed to verify data integrity using
MD5 (Message Digest Algorithm 5). MD5 is 128-bit cryptographic hash and if used properly it can be used to verify file authenticity and integrity. Example :
Input : md5sum /home/mandeep/test/test.cpp
Output : c6779ec2960296ed9a04f08d67f64422 /home/mandeep/test/test.cpp
Importance :
Suppose, anyone wants to install an operating system , so to verify if it's correct CD, it's always a good idea to verify .iso file using MD5 checksum, so that you don't end up installing wrong software (some sort of virus which can corrupt your filesystem).
Syntax :
md5sum [OPTION]... [FILE]...
It will print or check MD5(128-bit) checksum. It computes MD5 checksum for file "test.cpp" Output :
c6779ec2960296ed9a04f08d67f64422 /home/mandeep/test/test.cpp
Options :
-b :
read in binary mode
-c :
read MD5 from files and check them
--tag :
create a BSD-style checksum
-t :
read in text mode(it's by default)
The options which are useful when 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
-w :
warn about improperly formatted checksum files
Command usage examples with options :
Example 1: Store the MD5 checksum in file and then verify it.
# md5sum /home/mandeep/test/test.cpp > checkmd5.md5
It will store the MD5 checksum for test.cpp in file checkmd5.md5
# md5sum -c checkmd5.md5
It will verify the contents of file Output :
/home/mandeep/test/test.cpp: OK
After changing the contents of file checkmd5.md5, the output will be :
/home/mandeep/test/test.cpp: FAILED
md5sum: WARNING: 1 computed checksum did NOT match
Example 2: create a BSD-style checksum with --tag option
# md5sum --tag /home/mandeep/test/test.cpp
Output :
MD5 (/home/mandeep/test/test.cpp) = c6779ec2960296ed9a04f08d67f64422
Example 3: --quiet option, can be used when verifying checksum, don't print OK when verification is successful.
# md5sum -c --quiet checkmd5.md5
Don't produce any output, means it's successful. But if checksum don't match, it produces warning.
# md5sum -c --quiet checkmd5.md5
/home/mandeep/test/test.cpp: FAILED
md5sum: WARNING: 1 computed checksum did NOT match
Example 4: --warn option, it can be used for generating a warning for improperly formatted checksum files. content of file checkmd5.md5:
c6779ec2960296ed9a04f08d67f64422 /home/mandeep/test/test.cpp
Now, execute command with --warn option
# md5sum -c --warn checkmd5.md5
/home/mandeep/test/test.cpp: OK
It don't produce any warning. Now, do some formatting in file checkmd5.md5
c6779ec2960296ed9a04f08d67f64422
/home/mandeep/test/test.cpp
Now, execute the command
# md5sum -c --warn checkmd5.md5
Output :
md5sum: checkmd5.md5: 1: improperly formatted MD5 checksum line
md5sum: checkmd5.md5: 2: improperly formatted MD5 checksum line
md5sum: checkmd5.md5: no properly formatted MD5 checksum lines found
and if --warn is replaced with --strict option, it will exit non-zero for improperly formatted checksum lines
# md5sum -c --strict checkmd5.md5
md5sum: checkmd5.md5: no properly formatted MD5 checksum lines found
Similar Reads
let command in Linux with Examples The `let` command in Linux is a powerful tool used for evaluating arithmetic expressions on shell variables. It supports various operators and functionalities to perform calculations and manipulate values. Syntax of `let` command in Linux The basic syntax of the `let` is as follows. let [expression]
3 min read
ln command in Linux with Examples The 'ln' command in Linux is a powerful utility that allows you to create links between files. These links can either be hard links or soft (symbolic) links. If you're unfamiliar with these concepts, check out our detailed guide on Hard and Soft Links in Linux to understand their differences, use ca
3 min read
locate command in Linux with Examples locate command in Linux is used to find the files by name. There are two most widely used file-searching utilities accessible to users called to find and locate. The locate utility works better and faster than the find command counterpart because instead of searching the file system when a file sear
6 min read
look command in Linux with Examples The look command in Linux is used to display lines that begin with a specified string. It is especially useful for searching through large files or lists, as it helps you locate entries efficiently. By default, the look command performs case-insensitive matches and searches for exact prefixes. The l
3 min read
How to List All Block Devices in Linux | lsblk Command Understanding the storage devices connected to your Linux system is crucial for efficient system management. The 'lsblk' command, short for "list block devices," is a powerful tool that provides detailed information about block devices such as hard drives, solid-state drives, and other storage-relat
6 min read
lshw command in Linux with Examples The 'lshw' (List Hardware) command in Linux/Unix is a powerful tool for extracting detailed information about the system's hardware configuration. This tool retrieves data from files in the '/proc' directory and is capable of reporting on a wide array of components, including memory configuration, C
3 min read
lsmod command in Linux with Examples lsmod command is used to display the status of modules in the Linux kernel. It results in a list of loaded modules. lsmod is a trivial program which nicely formats the contents of the /proc/modules, showing what kernel modules are currently loaded. Syntax: lsmod Example: Run lsmod at the command lin
1 min read
How to List Open Files in Linux | lsof Command In the world of Linux, understanding and managing open files is crucial for system administrators and users alike. The Linux operating system provides a powerful utility called lsof (List Open Files) that allows users to gain insights into the files currently open on their system. In this article, w
7 min read
lsusb command in Linux with Examples The 'lsusb' command in Linux is a useful utility for displaying information about USB buses and the devices connected to them. It provides a detailed view of the USB hardware connected to your system, including details such as speed, bus number, device class, and type. This command is particularly v
2 min read
mailq Command in Linux with Examples mailq i.e. "mail-queue", this command in Linux prints the mail queue i.e. the list of messages that are there in the mail queue. You should have a mail-server setup on your Linux machine, to use this command, there are ways i.e MTA's(Mail Transfer agent) you can use like sendmail which uses the serv
3 min read