FC Command: Comparing Files in Windows
fc command, short for “File Compare,” is a command-line utility available in Windows operating systems. It allows users to compare the contents of two text files or binary files and identify any differences between them. The command is useful for verifying the integrity of files, identifying changes, and ensuring that files have been copied or transferred accurately. In this article, I have given an overview of the Fc command and its basic usage.
Syntax and Demonstration
syntax of fc command is very simple it takes two filenames as arguments,
file2, which are the files you want to compare. It then analyzes the contents of these files and reports their differences.
fc [options] [drive1:][path1]filename1 [drive2:][path2]filename2
OPTIONS: /A Displays only first and last lines for each set of differences. /B Performs a binary comparison. /C Disregards the case of letters. /L Compares files as ASCII text. /LBn Sets the maximum consecutive mismatches to the specified number of lines. /N Displays the line numbers on an ASCII comparison. /OFF[LINE] Do not skip files with offline attribute set. /T Does not expand tabs to spaces. /U Compare files as UNICODE text files. /W Compresses white space (tabs and spaces) for comparison. /nnnn Specifies the number of consecutive lines that must match after a mismatch. [drive1:][path1]filename1 Specifies the first file or set of files to compare. [drive2:][path2]filename2 Specifies the second file or set of files to compare.
Below I have shown the comparision in two files test1.txt and test2.txt with different options. The content of the two text files is as follows.
In the above two files, we can see that there are three differences that are, ‘O’ of output 4 in test2.txt is capital, output 9 exists in test1.txt only and output11 exists in test2.txt only.
Compare Text Files: To compare two text files, you can use the following command: This compares the whole files and displays the differences in them.
fc test1.txt test2.txt
Compare Binary Files: To compare two binary files, use the
/B option: This 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. The hexadecimal values for yy and zz represent the mismatched bytes from filename1 and filename2, respectively.
fc /B test1.txt test2.txt
Case-Insensitive Comparison: To perform a case-insensitive comparison of two files, use /c: This will not display the case-sensitive differences.
fc /C file1.txt file2.txt
Display Line Numbers for Differences: This will display line numbers during the comparison, use /N.
fc /N file1.txt file2.txt
fc command is a valuable tool for comparing the contents of two files, be it text or binary. Whether you’re verifying the accuracy of file transfers or identifying modifications, this command simplifies the process of finding differences between files. By understanding its options and using them appropriately, you can efficiently analyze files and ensure their integrity. For more articles like this check out the Batch-Man website and Github also follow us on Discord and Youtube.