Recursively md5sum all files in a directory tree

October 25, 2008 by Michael

After a server crash a wanted to compare all actual files with the backuped data. An easy way is to compare the md5 hashes like that:

First create recursively md5 hashes from all files in that directory:

find ./backup -type f -print0 | xargs -0 md5sum > /checksums_backup.md5

Then check the actual data:

md5sum -c checksums_backup.md5

I was lucky, no files where damaged.

11 comments

  1. tante wrote:

    find ./backup -type f -exec md5sum {} \;>> /checksums_backup.md5

    Läuft meiner Erfahrung nach oft schneller als xargs. Vielleicht in diesem Falle nicht ganz so relevant, aber für andere Fälle 😉

    Posted on October 25, 2008 at 2:31 PM | Permalink
  2. Michael wrote:

    Danke 🙂
    Ich hoffe, ich brauch’s nicht so schnell wieder.

    Posted on October 25, 2008 at 5:13 PM | Permalink
  3. sahar wrote:

    why when used md5sum i encountered to no such file or directory!?,…

    #!/bin/sh
    chksumfile=’tmp’
    `md5sum -c “$chksumfile”`
    ———————-
    # sh verifychksum.sh
    verifychksum.sh: line 3: chksum/ss/RecoverDataLinuxTrial.tar.gz:: No such file or directory
    ================================
    while when i run command line :

    # md5sum -c tmp
    chksum/ss/RecoverDataLinuxTrial.tar.gz: OK
    chksum/ss/zziplib-0.13.49-8.fc12.i686.rpm: OK
    chksum/RecoverDataLinuxTrial.tar.gz: OK
    chksum/zziplib-0.13.49-8.fc12.i686.rpm: OK
    chksum/s: OK
    chksum/chsum: OK

    Posted on June 19, 2011 at 8:14 AM | Permalink
  4. Benjamin wrote:

    Thanks, that worked flawlessly! Though I used the variant as proposed by tante.

    Posted on November 17, 2015 at 10:02 AM | Permalink
  5. This worked for me for a while, but I ripped a CD with apostrophe’s in the track names and the file shows up as missing in FlashSFV with the name garbled.

    [user@operation420.net Compton.ogg]# ls
    01. Intro.ogg 10. One Shot One Kill.ogg
    02. Talk About It.ogg 11. Just Another Day.ogg
    03. Genocide.ogg 12. For the Love of Money.ogg
    04. Itâs All on Me.ogg 13. Satisfiction.ogg
    05. All in a Dayâs Work.ogg 14. Animals.ogg
    06. Darkside_Gone.ogg 15. Medicine Man.ogg
    07. Loose Cannons.ogg 16. Talking to My Diary.ogg
    08. Issues.ogg checksums.md5
    09. Deep Water.ogg
    [user@operation420.net Compton.ogg]# grep “All in a Day” checksums.md5
    1623f1081bc98711d67ad32b5efd4680 ./05. All in a Dayâs Work.og

    Posted on February 21, 2016 at 8:51 PM | Permalink
  6. Steve wrote:

    Thanks. I used your command with “sum” and my own output filename and it worked!!
    Steve M.

    Posted on April 22, 2016 at 7:05 PM | Permalink
  7. tswaehn wrote:

    google “md5sum recursive” ging direkt hierher … und funktioniert prima – danke!

    Posted on October 4, 2016 at 7:58 PM | Permalink
  8. rfl wrote:

    great, thanks!

    Posted on April 20, 2017 at 9:13 PM | Permalink
  9. DockOfTheBay wrote:

    md5 isn’t secure, neither is sha1. Sha256 must be used. Thanks for the post though, still useful ten years later.

    Posted on August 23, 2018 at 10:39 PM | Permalink
  10. Michael wrote:

    True, md5 is not secure for password hashing and such. But for verifying just the integrity of a file locally, it is fully enough.

    Posted on September 1, 2018 at 9:30 AM | Permalink
  11. gregl83 wrote:

    Give paq a try got unique directory hashes: https://github.com/gregl83/paq

    Posted on June 29, 2023 at 6:05 AM | Permalink
3 Trackbacks/Pingbacks
  1. […] support going through each folder and checksuming each file and outputting the sums. Sure there are one line shell scripts/commands you can run but I was really looking for a way that would not require hacking about. I finally found what I was […]

  2. Recursively make md5sum on August 27, 2015 at 11:21 AM

    […] and sub-directory’s. The default command sadly doesn’t support recursion. Good thing, Michael Simons fixed it for me […]

  3. […] L'idée générale vient de Michael Simons. […]

Post a Comment

Your email is never published. We need your name and email address only for verifying a legitimate comment. For more information, a copy of your saved data or a request to delete any data under this address, please send a short notice to michael@simons.ac from the address you used to comment on this entry.
By entering and submitting a comment, wether with or without name or email address, you'll agree that all data you have entered including your IP address will be checked and stored for a limited time by Automattic Inc., 60 29th Street #343, San Francisco, CA 94110-4929, USA. only for the purpose of avoiding spam. You can deny further storage of your data by sending an email to support@wordpress.com, with subject “Deletion of Data stored by Akismet”.
Required fields are marked *