This entry is part 11 of 19 in the Bash-whacking series

Ever need to check if a directory is exactly the same as another (including file contents)?

span class="st0">'{print $1}'

This runs md5sum on the individual md5sum hashes of each file.

And if you need to exclude a directory from the comparison:

  • Dan

    This is exactly what I'm looking for, however, I'm not sure how to execute this command (I'm not really good at bashing). For instance, in the above example that you post:

    [code]find . -type f -exec md5sum {} + | awk '{print $1}' | sort | md5sum[/code]

    Would I enter the directory I want to compare after "find", therefore making it:

    [code] find /media/drive1/folder1 /media/drive2/folder2 . -type f -exec md5sum {} + | awk '{print $1}' | sort | md5sum[/code]

    Is this correct? Currently, I'm using a tedious method where I run separate commands in two terminals:

    find '/media/drive1/folder1' -type f -exec md5sum "{}" \; > master.txt
    find '/media/drive2/folder2' -type f -exec md5sum "{}" \; > slave.txt

    Then I run calc, separate the columns and compare the md5sum and sort the results in descending order. Not very efficient but it does the trick. I'd like to verify your method.

  • Kelvin

    Hey Dan! What I do is to go to the directory I want to compare, in your case, /media/drive1/folder1, then run the find command.

    i.e.

    cd /media/drive1/folder1
    find . -type f -exec md5sum {} + | awk '{print $1}' | sort | md5sum

    cd /media/drive1/folder2
    find . -type f -exec md5sum {} + | awk '{print $1}' | sort | md5sum

    Let me know how this goes!

  • Nicole Lee
  • Shiba

    Very useful, but I removed awk '{print $1}' because same files with different filenames have the same md5 :)