Monday, April 29, 2024
53
rated 0 times [  53] [ 0]  / answers: 1 / hits: 67526  / 3 Years ago, sun, may 2, 2021, 12:54:44

I can check md5sum hash of a file from a terminal as,



$ md5sum my_sensitive_file
8dad53cfc973c59864b8318263737462 my_sensitive_file


But the difficult part is to compare the hash value with exact one.



It is difficult to compare the 32 characters output with original/exact hash value by any human for a large numbers of files. First of all the job would be very monotonous and there are big scope of errors.




Is it possible to automate the comparing process, preferably in CLI?



More From » command-line

 Answers
4

For example I have a file called test_binary.



MD5 sum of file test is ef7ab26f9a3b2cbd35aa3e7e69aad86c



To test it automatically run this:



$ md5sum -c <<<"ef7ab26f9a3b2cbd35aa3e7e69aad86c *path/to/file/test_binary"
test_binary: OK


or



$ echo "595f44fec1e92a71d3e9e77456ba80d1  filetohashA.txt" | md5sum -c -


Quote from man



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


Quote from wiki




Note: There must be two spaces between each md5sum value and filename
to be compared. Otherwise, the following error will result: "no
properly formatted MD5 checksum lines found".




Link to wiki



Also you can just read md5 hashes from file



$ md5sum -c md5sum_formatted_file.txt


It is expecting file with format:



<md5sum_checksum><space><space><file_name>





About * and <space> after MD5 sum hash. There is little note in man:



 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.


And here is link to stackoverflow where I found answer on question, why should we, sometimes, distinguish binary files and text files.





[#26211] Sunday, May 2, 2021, 3 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
bjecterless

Total Points: 59
Total Questions: 96
Total Answers: 105

Location: Argentina
Member since Thu, Mar 18, 2021
3 Years ago
bjecterless questions
;