Compare the contents of two files or sets of files. Display any lines which do NOT match.
Syntax FC [options] [drive1:][path1] filename1 [drive2:][path2] filename2 Options /A Abbreviate the output of an ASCII comparison, display only first and last lines for each set of differences. /B Perform a binary comparison. FC compares the two files byte by byte and does not attempt to resynchronize the files after finding a mismatch. This is the default mode for comparing files that have the following file extensions: .exe, .com, .sys, .obj, .lib, or .bin. /C Do a case insensitive string comparison /L Compare the files in ASCII mode. Fc compares the two files line by line and attempts to resynchronize the files after finding a mismatch. This is the default mode for comparing non binary files, see /B. /LBn Set the n number of lines for the internal line buffer. The default length of the line buffer is 100 lines. If the files being compared have more than this number of consecutive differing lines, FC cancels the comparison. /N Display line numbers during an ASCII comparison. /T Prevent FC from converting tabs to spaces. The default behavior is to treat tabs as spaces, with stops at each eighth character position. /U Compares files as Unicode text files. /W Compress white space (that is, tabs and spaces) during the comparison. If a line contains many consecutive spaces or tabs, /w treats these characters as a single space. When used with the /W command-line option, FC ignores (and does not compare) white space at the beginning and end of a line. /nnnn The a number of consecutive lines that must match before FC considers the files to be resynchronized. If the number of matching lines in the files is less than nnnn, FC displays the matching lines as differences. The default value is 2. [ drive1 : ][ path1 ] filename1 The location and name of the first file you want to compare. Filename1 is required. [ drive2 : ][ path2 ] filename2 The location and name of the second file you want to compare. Filename2 is required. Wildcards ( * and ? ) may be used with filename1 or filename2, FC will then compare all the matching files.
Powershell also has an Alias FC for the Format-Custom cmdlet, therefore to run the 'old' FC under PowerShell you can explicitly run C:\windows\system32\fc.exe
FC will set an ErrorLevel as follows:
-1 Invalid syntax (e.g. only one file passed)
0 The files are identical.
1 The files are different.
2 Cannot find at least one of the files.
For an invalid switch (with two passed files) an error message is printed but the errorlevel is not changed.
The messages returned by FC are language/locale dependent, so to reliably identify 2 identical files use redirection syntax:FC File1.txt File2.txt >NUL && Echo Same || Echo Different or error
When FC is used for an ASCII comparison, it will display differences between two files in the following order:
- Name of the first file
- Lines from filename1 that differ between the files
- First line to match in both files
- Name of the second file
- Lines from filename2 that differ
- First line to match
/B displays mismatches found during a binary comparison as follows: xxxxxxxx: yy zz
The value of xxxxxxxx specifies the relative hexadecimal address for the pair of bytes, measured from the beginning of the file. Addresses start at 00000000.
The hexadecimal values for yy and zz represent the mismatched bytes from filename1 and filename2, respectively.
When comparing binary files that are larger than available memory, FC compares both files completely, overlaying the portions in memory with the next portions from the disk.
Make a binary comparison of two DLL files:
C:\> FC /b new.dll old.dll
Make an ASCII comparison of two text files and display the result in abbreviated format:
C:\> FC /a C:\demo\input.txt H:\work\output.txt
# Oh lord won't you buy me a Mercedes Benz, my friends all drive Porsches, I must make amends # - Janice Joplin
COMP - Compare two files and display any characters which do NOT match
FIND - Search for a text string in a file
FINDSTR - Search for strings in files
WinDiff - GUI to compare files
Powershell: Compare-Object - Compare the properties of objects, e.g. compare content of files.
Equivalent bash command (Linux): cmp - Compare two files