Any relevance to check if files are identical (ie diff ) on *nix

(imported topic written by SystemAdmin)

I need to compare all lines of two files to return true/false if the files are the same.

I can compare size of file, but prefer using the unix/linux diff. If nothing is returned, they are identical. But I want a true result

(imported comment written by MarkA.Stevens)

Create a tuple of the two files:

(lines of file “/etc/passwd” as string) ,(lines of file “/etc/passwd” as string)

…long long output omitted here …

Compare each item:

Q: (item 0 of it is not equal to item 1 of it) of ((lines of file “/etc/passwd” as string) ,(lines of file “/etc/passwd” as string))

A: False

A: True

Use conjunction (AND) all the trues and falses and return one true or false:

Q: if conjunction of (item 0 of it is equal to item 1 of it) of ((lines of file “/etc/passwd” as string) ,(lines of file “/etc/passwd” as string)) is equal to (true) then (true) else (false)

A: False

T: 63739

I Hope This Helps …Mark A. Stevens

(imported comment written by NoahSalzman)

You can also just do this:

Q: (sha1 of file “/Users/noah/pass1”),(sha1 of file “/Users/noah/pass2”)

A: ec6f0c002f475a225f357c8150ad2bd7b3bad6ad, ec6f0c002f475a225f357c8150ad2bd7b3bad6ad

Q: (sha1 of file “/Users/noah/pass1”) = (sha1 of file “/Users/noah/pass2”)

A: True

(imported comment written by SystemAdmin)

I’d recommend checking both sha1 & file size, and make sure they both match.

This is still not %100 perfect, as there could still be hash collisions, but they are very rare if both the size and sha1 match. If you want to be certain, you may consider checking the size, and compare, then check sha1 and compare, then check line by line and compare. That way you go from least resource heavy to most resource heavy and only do the resource heavy ones if the previous checks pass.

The level of checks needed depends on your use case. I would avoid full line by line comparison in most cases, as it could take a long time for large files.