FC Command - Compare Files

In this short guide we are going to learn how to compare files using the FC command from the windows command line (cmd). Lets get started!

What We'll Learn:

Welcome!
This guide is all about comparing files directly from the windows command line.

  • We’ll start by learning, exactly what the FC command is and what function it serves.
  • We’ll then learn, how to use the FC Command to compare two files.
  • How to take advantage of wildcards and compare a number of files all at once.
  • And finally, we’ll take a look at a few useful parameters and numerus usage examples.

Lets get started!

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 with our computers username).

FC "C:\Users\Desktop\File1.txt" "C:\Users\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.

Summary:

  • FC stands for file compare and as the name implies it can be used to make binary or text file comparisons.
  • To view the differences between two files use the FC command without any parameters.
  • Use wildcards instead of names for your files to compare every file in a directory with one another.

That's It!

You now know how to use the Fc command to compare files directly from the command prompt.

If you liked this short guide take a look at a few of our other posts related to the windows command line, or if you really liked it consider enrolling in our video course where you will learn the ins and outs of the Windows command Line.

Windows Command Line

Dont Stop Learning!

Windows Command Line Course

No more searching or memorizing commands! This course has everything you need to start learning about the windows command line along with batch scripting.

Read More:

Comments:

Leave a Reply

Your email address will not be published.

Take Your Skills to the next level!

Become one of our beloved students by enrolling into one of our courses. Get started now!

Special Offer!

90% Off!

Windows Command Line Course.