Could we help you? Please click the banners. We are young and desperately need the money
Comparing file hashes is a great way to verify file integrity and protect against tampering. If you produce a hash sum from a file, then do it again using the same file at a later time and compare the hashes, you can find out whether the file has been manipulated in the meantime or not. The hash sum is like a signature that guarantees a file's legitimacy or highlights its lack thereof.
In the past, you'd frequently see MD5 be used for this sort of task (checksum generation). It's fast and does it's job well but is not without its flaws. Due to security concerns with the dated MD5 algorithm, we'll be employing the more modern SHA-256 instead for this guide.
To generate a hash string with SHA-256, use the following command (replacing "filename" with the name of the file you wish to hash):
sha256sum filename
If done right, you should receive a string that follows this pattern:
hash-sum filename
564caeae854c1f69eac45be77a8b039a4af12b63f0492e1a292e5cf39702083b filename
If you so desire, you can directly store the string inside a hash file when making the hash sum:
sha256sum filename > filename.hash
Finally, let's learn how to compare hashes.
If you have a hash string, use the following command template:
echo "hash-sum filename" | sha256sum -c
echo "564caeae854c1f69eac45be77a8b039a4af12b63f0492e1a292e5cf39702083b filename" | sha256sum -c
Should you have a hash file, use this example instead:
sha256sum -c filename.hash
If your hash comparison succeeds (given and actual file hash sum are equal), you'll see a message that reads something along the lines of this:
filename: OK
In case of failure, you'll see:
filename: FAILED