4

I have two 4GB temporary files.

I did a quick visual inspection using a hex editor and see they appear to be the same. Is there a command I can use in something like PowerShell to binary compare the two so I can be certain they are the same?

1

4 Answers 4

5

As @dhiwakar-ravikumar already answered, you can use the "file compare" (fc) Windows command to compare 2 files (or sets of files), and use the /b parameter to do a binary comparison.

However, it should be noted that contrary to the "cmd" command shell, in PowerShell, the command has to be spelled out as fc.exe to avoid the "fc" alias to Format-Custom to take precedence. Like so:

fc.exe /b [<Drive1:>][<Path1>]<FileName1> [<Drive2:>][<Path2>]<FileName2>

Also note that if the extension of the files to compare is one of .exe, .com, .sys, .obj, .lib or .bin, a binary comparison is performed by default and the /b parameter can be omitted to the same result.

2
  • I initially tried to edit @dhiwakar-ravikumar 's answer to include the .exe extension to the command for PowerShell (which OP specifically asked about) and update the documentation link, but it was rejected as deviating too much from the original answer intent, so I tried to post it as a new answer as I think it is relevant information (someone even asked in a comment). When downvoting, I'd sincerely appreciate info on why and / or advice on a better couse of action.
    – desseim
    Commented Feb 10, 2020 at 14:10
  • Hi desseim, thanks for your answer. I came back to this and found out that YEAH powershell won't take fc and your answer has a heck of a lot more information. Thanks
    – chrips
    Commented Feb 12, 2020 at 1:36
4

There is a command in Windows which can give you a binary comparision of two files

fc /b <filename1> <filename2>

For more information - https://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/fc.mspx?mfr=true

This works equally well on Windows 7

If you're looking for tools , there is an answer already - https://stackoverflow.com/questions/8166697/tool-for-comparing-2-binary-files-in-windows

1
  • 1
    What about Win10? The 1st link also does not exit any more!
    – mini
    Commented Mar 23, 2019 at 18:59
0

Internal compare tool of Total Commander 64bit works fine on files over 2GB. (File -> Compare by content)

0

fc.exe works great in PowerShell but just for completeness, I'm adding the PowerShell docs version of compare below:

Compare-Object -ReferenceObject $(Get-Content textout.txt) -DifferenceObject $(Get-Content textout1.txt)
2
  • How would you use it to compare binary files ? As is it treats them as text (and outputs the whole binary "garbage"). I tried the AsByteStream parameter mentioned in the documentation but it was very memory hungry and inefficient (I didn't get it to terminate comparing ~1MiB files on my setup, even after several minutes).
    – desseim
    Commented Feb 12, 2020 at 17:03
  • 1
    @desseim Uh oh, I guess I'll have to look into it and update!
    – chrips
    Commented Feb 12, 2020 at 23:00

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .