Compare Files - Using The Command Line
(FC, Windows, CMD, DOS)

What Is The File Compare (FC) Command?

If you are a programmer or a writer it is very useful to know if there are any differences between two files.
You can use the command line to display any differences using the FC command.
FC stands for file compare and as the name implies it can be used to make binary or text file comparisons on both ASCII and Unicode text.
We are going to learn how to do just that in this short guide.
If you would like to follow along, open your command line and navigate to a directory of your choice (i.e. Desktop) and use the echo command along with a redirector to create two files.

echo Hello > File1.txt & echo Coodbye > File2.txt

Two files should immediately be created in you current directory.
Now that our files have been created lets learn how to compare them using the FC command.

How To Use FC To Compare Files

Using the FC command is easy, to compare the files we just created simply type the FC command followed by the names of our files one after the other.

FC File1.txt File2.txt
Compare Files - Using The Command Line (FC, Windows, CMD, DOS)

The FC command will immediately output every line that is different between the two files, allowing you to quickly and efficiently assess any differences. 
If the command line was not able to locate your files even tho you are sure they are located in he same directory as the command line, it might have been so because the names of your files contain spaces within their name.
If that’s the case you need to surround the names of your files with quotes.
That’s because the quotes tell the command line that the spaces separating the words do not constitute an additional parameter and are just a continuation of the name of your file.
This is what the command should look like:

FC "File1.txt" "File2.txt"

You can use the FC command to compare files that are located in a different directory than the one you are currently on, by typing their location followed by a backward slash and the name of your file instead of the name of your file directly.

FC "C:\Users\<Username>\Desktop\File1.txt" "C:\Users\<Username>\Desktop\File2.txt"

Replace <Username> with your computers name.
The FC command by default differentiates words based on their casing, meaning, for example, that the words “Awesome” and “awesome” will be deemed different by the FC command because of their casing difference.
If this is not the desired behavior use the /c parameter to make the FC command ignore any such differences.

FC /c "File1.txt" "File2.txt"

Compare Multiple Files At Once

So far we have been using the FC command to compare only two files, the FC command can be used to make multiple comparisons with just one command with the use of wildcards.
Wildcards are special symbols that take the place of characters or words.
For example:

FC "*.txt" "File2.txt"

Every text file in the current directory will be compared against “File2.txt”.
As you can see i have enclosed the wildcard in quotes because some of the names of our files in the current directory might contain spaces.
We can even use the FC command to compare every text file in the current directory against one another.

FC "*.txt" "*.txt"

Binary File Comparison

Apart from comparing the text between two files we can use the FC command to perform binary comparisons as well.
To compare the binary data between two files you need to use the FC command along with the /b parameter.
This is what the command should look like.

FC /B "File1.txt" "File2.txt"
Compare Files - Using The Command Line (FC, Windows, CMD, DOS)

Useful Parameters Include:

  • /C Which will disregard any casing differences between the strings.
  • /A Which will only show the first and last lines for each set of differences.
  • /B Will perform a binary comparison.
  • /L Will compare the files as ASICC text.
  • /LB Directly followed by a number will limit how many different lines the FC command will look through before aborting.

Examples:

View the differences between two files.

FC "File1.txt" "File2.txt"

View the differences between two files that are located in the desktop directory (replace <Username> with our computers username).

FC "C:\Users\<Username>\Desktop\File1.txt" "C:\Users\<Username>\Desktop\File2.txt"

Compare every text file in the current directory with “File2.txt” while ignoring any casing differences.

FC /c "*.txt" "File2.txt"

Compare every text file in the current directory against one another.

FC "*.txt" "*.txt"

Compare two text files while ignoring any casing differences and limiting the amount of different lines that the FC command will look through before aborting, to one.

FC /c /LB1 "File1.txt "File2.txt"

Perform a binary comparison between two files.

FC /B "File1.txt" "File2.txt"

Help Output:

Compares two files or sets of files and displays the differences between
them

FC [/A] [/C] [/L] [/LBn] [/N] [/OFF[LINE]] [/T] [/U] [/W] [/nnnn]
[drive1:][path1]filename1 [drive2:][path2]filename2
FC /B [drive1:][path1]filename1 [drive2:][path2]filename2

/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.

Read Next: