How to compare two files using command prompt in Windows

Comparing the difference between two text-based files using windows command prompt

If you work on a lot of text-based files, then sometimes you modify a specific file and get a new version of the old version. Sometimes you need to compare two files to see the differences. These tasks repeatedly happen in software or web development, design or whether it is about coding or programming.

Probably, you create a lot of versions of a source file while updating your software or updating your design layouts. And you name them like this: app.c, app-new.c, app-final.c, etc. But in case, you want to know, what you have been changed or updated from the previous versions.

As your source files may contain hundreds of thousand lines of code. So it is tough to find out the differences between the two versions. If you are running Microsoft Windows, then it comes with a built-in file comparing tools, that is based on the command line or command prompt.

In the Windows command prompt, using the FC command you can easily compare two files. FC stands for File Compare. This tool will execute the difference between the two mentioned files. Now we will see, how to compare two files using FC command in the windows command prompt. Here we go;

How to compare two files using command prompt

First of all, open up your terminal by typing in cmd in the Run window. And navigate to the folder where all of your versions are exist. In my case, I have saved my versions on the desktop. So I am changing the directory to Desktop using cd Desktop command.

I have created two C program files on my desktop called app-old.c and app-new.c. Now we are going to compare them using the FC command.

The app-old.c looks like this:

App old - Compare two files using command prompt windows progracoding

And app-new.c looks like this;

App new - Compare two files using command prompt using command prompt

After navigating the Desktop folder, run the following command to find the difference.

FC app-old.c app-new.c

After running the above command, windows will instantly start the comparing processes. After processing the entire file, it will only execute the block of codes, where the code appears to be different.

In my case, after running the command for app-old.c and app-new.c, we will get the following result in the command line:

cmd - comparing two files using commad prompt in windows

After execution, notice that the only block is showing where I made a simple string difference”Hello World” and Hello, new World”  in the HelloWorld function. In this way, you can compare any kind of text-based files of any size. It does not matter, how many lines contain your files. Windows will take care of it automatically.

Posted in