Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

motulist

macrumors 601
Original poster
Dec 2, 2003
4,236
611
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?
 
The Terminal "diff" command will do this quite happily.

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!
 
Diff checks the contents of the files too, so even if two files are named identically they will show as different in the results.
 
Diff checks the contents of the files too, so even if two files are named identically they will show as different in the results.

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
 
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.
 
if you have sub-directories in the folders you have to use the "--recursive" flag to include them, which would go before the folders.

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
 
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.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.