Skip to content

md5sum command in Linux

The md5sum command in Linux is used to calculate and verify checksums of files. It computes and displays the MD5 checksum of a file, which can be used to check the integrity of the file. The output consists of a 32-character hexadecimal number. The md5sum command is commonly used to compare MD5 values of files to ensure they have not been altered or corrupted. By comparing the checksums before and after transferring files, users can verify data integrity and detect any potential errors during the file transfer process.

md5sum Syntax:

Terminal window
md5sum [option] [file]

Linux md5sum Options:

OptionDescription
-bTreat files as binary
-cCheck MD5 sums from a file
-tText mode (default)

md5sum Parameters:

ParameterDescription
fileThe file to compute or check the MD5 checksum for

How to use md5sum command:

Create MD5 Hash for a Single File

Terminal window
md5sum file.txt

Calculates the MD5 hash for a single file named “file.txt”.

Verify Integrity of a File Using MD5 Hash

Terminal window
md5sum -c sum.txt

Verifies the integrity of files listed in “sum.txt” by checking their MD5 hashes.

Generate MD5 Hashes for Multiple Files

Terminal window
md5sum file1.txt file2.txt

Calculates the MD5 hashes for multiple files, “file1.txt” and “file2.txt”.

Display Only the Hash (No Filename)

Terminal window
md5sum -b file.txt

Shows only the hash without the filename for the file “file.txt”.

Verify MD5 Hash Without Printing OK

Terminal window
md5sum -q -c sum.txt

Checks MD5 hashes listed in “sum.txt” and suppresses the “OK” message for matched files.

Check MD5 Hashes Recursively in a Directory

Terminal window
md5sum -c MD5SUMS --status -s

Recursively checks MD5 hashes in a directory using the “MD5SUMS” file, and only displays errors without a detailed output.

Generate MD5 Hash with Custom Format

Terminal window
md5sum --format=file.txt

Generates the MD5 hash for “file.txt” and outputs the result in a custom format.

Create MD5 Hash for a Password

Terminal window
md5sum <<< "password"

Generates the MD5 hash for the provided password “password”.

How do I use md5sum in Linux?

To use the md5sum command in Linux, execute the following command:

Terminal window
md5sum <file_path>

What is the purpose of the md5sum command?

The md5sum command is used to calculate and verify the MD5 checksum of a file in Linux.

How can I verify the integrity of a downloaded file using md5sum?

To verify the integrity of a downloaded file using md5sum, compare the generated MD5 checksum with the original checksum provided by the file source.

Terminal window
md5sum -c <original_checksum_file>

Can md5sum be used to compare two files?

Yes, you can use md5sum to compare two files by generating the MD5 checksum for each file and then comparing the checksum values.

Terminal window
md5sum <file1> <file2>

How do I output only the MD5 checksum value without the filename?

To output only the MD5 checksum value without the filename when using md5sum, you can use the -b or --binary option.

Terminal window
md5sum -b <file_path>

Is it possible to generate MD5 checksums for multiple files at once?

Yes, you can generate MD5 checksums for multiple files at once by providing the list of file paths as arguments to the md5sum command.

Terminal window
md5sum <file1> <file2> <file3>

How can I save the MD5 checksum output to a file in Linux?

To save the MD5 checksum output to a file in Linux, you can use output redirection with the md5sum command.

Terminal window
md5sum <file_path> > checksum.txt

How do I display the MD5 checksum in a human-readable format?

To display the MD5 checksum in a human-readable format when using md5sum, you can use the -w or --warn option.

Terminal window
md5sum -w <file_path>

Applications of the md5sum command

  • Verifying file integrity
  • Generating checksums for files
  • Comparing checksums to detect data corruption
  • Creating unique identifiers for files