Linux Generate A MD5 String or Hash with md5sum Command

The md5sum command in Linux can be used to generate an MD5 hash or message digest of a file. An MD5 hash is a fixed-length string of characters that is generated from the contents of a file. The hash can be used to verify that the contents of a file have not been modified.

Here’s how you can generate an MD5 hash with the md5sum command:

  1. Open a terminal window.
  2. Change to the directory where the file you want to generate an MD5 hash for is located.
  3. Run the following command, replacing filename with the name of the file:
    md5sum filename

The md5sum command will generate an MD5 hash for the file and display it in the terminal window, along with the name of the file. For example:

$ md5sum file.txt
29dd80de1d27e12e77dc2b3f3b3a3c33 file.txt

In this example, the MD5 hash of the file file.txt is 29dd80de1d27e12e77dc2b3f3b3a3c33. If you have an MD5 hash that you want to compare with the hash of a file, you can use the md5sum command with the -c option to check the hash:

$ md5sum -c file.txt.md5
file.txt: OK

In this example, the -c option tells md5sum to check the hash of file.txt against the hash in the file file.txt.md5. The message file.txt: OK indicates that the hash of file.txt matches the hash in file.txt.md5.

Leave a Comment