Reputation: 85
I have no idea how to check the integrity of file on Unix/Linux by hashing algorithm,md5. I attent to develope the bash script to check md5 of desired files in each specific folder(include sub folders too) on Linux. So my question is it possible to do? The background is to check the integrity of file before to do change on system.
Thank you for your advicement, Ponomy
Upvotes: 7
Views: 27229
Reputation: 10868
it's better to use sha256sum or sha512sum which is included on most linux systems by default:
$ sha256sum file
a9c558e2aee7e36080457eabaf5e82b5bcb4f168a552b2c2757121bd72844abc file
$ sha512sum file
b6d831ff00d55ab467e2c63e27e229f4b1f6e76542709260ead9cde6f426fe76a985ee52cc31b1ab68035d3a37841171c658e3c79cb673566a555d4ab45ff46d file
Upvotes: 1
Reputation: 80
This is my script to check integrity all file from 2 directory, with md5sum. You can change directory name that you want to check:
#!/bin/sh
cd persediaan
find . -exec md5 {} \; | sort > /tmp/file1_md5_sort
cd -
cd tmp/persediaan
find . -exec md5 {} \; | grep -v Tag | sort > /tmp/file2_md5_sort
cd -
diff /tmp/file1_md5_sort /tmp/file2_md5_sort | grep -v CVS | grep MD5
Upvotes: 0
Reputation: 61
md5sum is not recursive which was specifically requested in his question. Maybe find /path/to/files -type f -print0 | xargs -0 md5sum > checksum.md5
would be sufficient, but I prefer the hashdeep tools.
Use md5deep -r /path/to/files > checksum.md5
. Then later on, you can use md5sum -c checksum.md5 | grep -v ' OK$'
to check for any changes. Of course, this doesn't detect any newly added files. You could also use sha256deep and sha256sum if you're paranoid. ;-)
You could also use md5deep -rx checksum.md5 /path/to/files
to do the check. Alternatively, you could use hashdeep -r /path/to/files > hashes
and then hashdeep -ravvk hashes /path/to/files
to "audit" the files. I'm not really a fan of the way the hashdeep tools do their checks and audits, but you might think it's great, so there you go. :-)
Of course, none of this checks file meta data (time stamps, ownership, permissions, et cetera). But then you're getting into things like TripWire or AIDE.
Upvotes: 6