Compare files?

Discussion in 'Mac Basics and Help' started by motulist, Jan 24, 2010.

  1. motulist macrumors 601

    motulist

    Joined:
    Dec 2, 2003
    #1
    I'm looking for a way to make sure that the contents of two folders are exactly identical. I search the forum and google, and I saw a few ways that sound like they check that the filenames are the same in both directories, but don't actually compare the files themselves to be bit-for-bit identical (though I could be wrong in my understanding of what they're doing).

    Do you know of a program or unix command that'll do a bit-for-bit file comparison of all the files in 2 folders?
     
  2. Queso macrumors G4

    Joined:
    Mar 4, 2006
    #2
    The Terminal "diff" command will do this quite happily.
     
  3. motulist thread starter macrumors 601

    motulist

    Joined:
    Dec 2, 2003
    #4
    Will it? Huh. In my quick skimming of the google results for that command, I got the impression that it was just checking the file names and directory locations, rather than doing a bit-for-bit comparison. Hmmm...

    *goes to check google results again*


    EDIT: Well, you were right, I was wrong. There goes my reading comprehension grade! Doh!
     
  4. Queso macrumors G4

    Joined:
    Mar 4, 2006
    #5
    Diff checks the contents of the files too, so even if two files are named identically they will show as different in the results.
     
  5. motulist thread starter macrumors 601

    motulist

    Joined:
    Dec 2, 2003
    #6
    Thanks so much. Can you also just give me a quick non-techie example of how to properly execute a diff comparison of two folders' contents? Do I simply write this?

    Code:
    
    diff folder_A folder_B   
    
    
     
  6. Queso macrumors G4

    Joined:
    Mar 4, 2006
    #7
    Pretty much yeah. A good example would be of two folders named Stuff, one in your Documents folder and the other on your Desktop

    diff ~/Documents/Stuff ~/Desktop/Stuff

    (The ~ means your home directory)

    Oh and BTW, if you have sub-directories in the folders you have to use the "--recursive" flag to include them, which would go before the folders.
     
  7. motulist thread starter macrumors 601

    motulist

    Joined:
    Dec 2, 2003
    #8

    Thanks a bunch! :)

    EDIT: And drag-n-drop terminal command file locations FTW!!!
     
  8. Queso macrumors G4

    Joined:
    Mar 4, 2006
    #9
    LOL. You know, until now I never realised OSX did that :D
     
  9. motulist thread starter macrumors 601

    motulist

    Joined:
    Dec 2, 2003
    #10
    Hah! Cool! I'm glad I could help you back in return! :D
     
  10. motulist thread starter macrumors 601

    motulist

    Joined:
    Dec 2, 2003
    #11
    Oh, one more thing, I just want to check how to do the sub-directories flag correctly. Would it go like this?

    Code:
    
    diff folder_A folder_B --recursive
    
    
     
  11. Queso macrumors G4

    Joined:
    Mar 4, 2006
    #12
    No. Like this:-

    diff --recursive folder_A folder_B
     
  12. Cynicalone macrumors 68040

    Cynicalone

    Joined:
    Jul 9, 2008
    Location:
    Okie land
    #13
    I didn't know OS X did that. Very nice.
     
  13. motulist thread starter macrumors 601

    motulist

    Joined:
    Dec 2, 2003
    #14
    Ah, thanks. I'm glad I asked.


    It's a triple help win!
     
  14. Queso macrumors G4

    Joined:
    Mar 4, 2006
  15. motulist thread starter macrumors 601

    motulist

    Joined:
    Dec 2, 2003
  16. motulist thread starter macrumors 601

    motulist

    Joined:
    Dec 2, 2003
    #17
    Okay Queso (or anyone else), here's a little bit of a deeper question. I've been copying files onto my hard drive from aging CD-Rs so I can preserve my data, and diff recursive has been working beautifully to make sure I'm getting perfect file copies off of my CD-Rs. However, now I've come across a damaged CD-R. So I copied all of the files that the Finder's copy function didn't puke on, and now I want to use diff to see if all the files that transfered over without an error alert did, in fact, actually come across intact.

    The problem now is that when I run diff, it terminates as soon as it gets to a file that the optical drive returns with an I/O error. So I can't check if the rest of the files after the damaged region were transfered over properly. And it's funny, because now is the situation where diff can really come in handy!

    So the question is this: Is there a way to set diff to not terminate as soon as it reaches a file reporting with an I/O error?


    p.s. I skimmed Diff's MAN page, but I am out of my league.
     

Share This Page