MD5 Checksum for Directory

If you have a bunch of files in two directories and you want to compare two directories to see if the files in the two directories are identical, here is what you can do.

find . -type f -exec md5sum {} + | LC_ALL=C sort | md5sum

Here is the output.

3c8cbc780e68eb675d8d8d7ec9135389

When I ran the command above in a different directory with the same files, it returned the same hash. So it seems to work.

I’m not going to remember the command, so I will put that in my .zshrc file as alias.

alias md5='find . -type f -exec md5sum {} + | LC_ALL=C sort | md5sum'

However, this command returns different hash if the file name is different and the contents is the same. Hmmm, is it a good thing? Maybe it’s OK because you want to regard the directories are different if they have different file names but the same content.

Reference: https://www.baeldung.com/linux/directory-md5-checksum

Leave a Reply

Your email address will not be published.