[windows] What is the Windows equivalent of the diff command?

I know that there is a post similar to this : here.
I tried using the comp command like it mentioned, but if I have two files, one with data like "abcd" and the other with data "abcde", it just says the files are of different sizes. I wanted to know where exactly they differ. In Unix, the simple diff tells me which row and column, the comp command in windows works if I have something like "abd" and "abc". Not otherwise. Any ideas what I can use for this?

This question is related to windows cmd diff

The answer is


The windows equivalent to the diff command is the fc (File Comapre) command.

Here are the basic steps to do so:
1. Keep the two files in a folder (Example file1.html and file2.html)
2. Launch command prompt
3. Type fc file1Location file2Location

Have found a detailed tutorial on the same:

http://www.howtogeek.com/206123/how-to-use-fc-file-compare-from-the-windows-command-prompt/


Well, on Windows I happily run diff and many other of the GNU tools. You can do it with cygwin, but I personally prefer GnuWin32 because it is a much lighter installation experience.

So, my answer is that the Windows equivalent of diff, is none other than diff itself!


I don't know if the following tool is exatly what you need. But I like to use, for specific files, some online tool. This way I can use it regardless of the operational system. Here is a example: diffchecker.com

But for my needs, I guess the best tool to track changes and logs of my project's files is GIT. If you work in a team, you can have some repo online in a server of yours, or use it with Bitbucket or Github.

Hope it helps somebody.


Another alternative is to download and install git from here. Then, add the path to Git\bin\ to your PATH variable. This will give you not only diff, but also many other linux commands that you can use from the windows command line.

You can set the PATH variable by right clicking on Computer and selecting Properties. Then you can click on Advanced System Settings on the left side of the screen. In the pop up, click Environment Variables and then either add or update the PATH variable in your user variables with Git\bin\

Git diff documentation


I've found a lightweight graphical software for windows that seems to be useful in lack of diff command. It could solve all of my problems.

WinDiff http://www.grigsoft.com/download-windiff.htm


FC works great by in my case it was not helpful as I wanted just the lines that are changed. And FC give additional data like file name, same lines and bilateral comparison.

    >fc data.txt data.txt.bak   
    ***** DATA.TXT
    ####09
    ####09
    ####09
    ***** DATA.TXT.BAK
    ####09
    ####08
    ####09

but in my case I wanted only the lines that have changed and wanted those lines to be exported to different file, without any other header or data.

So I used "findstr" to compare the file :

findstr /V /G:data.txt.bak data.txt >DiffResult.txt

where :

data.txt.bak is the name of old file

data.txt is the name of new file

DiffResult.txt contains the data that is changed i.e just one line ####09


Winmerge has a command line utility that might be worth checking out.

Also, you can use the graphical part of it too depending on what you need.


fc. fc is better at handling large files (> 4 GBytes) than Cygwin's diff.


The reason you getting the error with COMP is that the utility assumes the files that you are comparing are of the same size. To overcome that you can use th '/n' option with which you can specify the number of lines you want to compare. (see the options supported by comp by typing 'comp /?' on the command line. so your command would look like :

C:\>comp "filepath1" "filepath2" /a /l /n=(the number of lines you want to compare) /c 

This should solve your problem if you wanna stick to using COMP. But this will be a problem for really large files.

Though comp is an option, but I feel it is primitive and FC is a better option. you can use FORFILES and FC together to probably make a really good filecompare utility if you require one on a frequent basis.

FC is used this way for ref:

C:\>fc /c(case insensistive) /lbn(number of errors allowed before you wanna stop compare) /n(display line number) "filename1" "filename2"

there are many options available which you can see by 'fc /?' hope this helps


DiffUtils is probably your best bet. It's the Windows equivalent of diff.

To my knowledge there are no built-in equivalents.


There's also Powershell (which is part of Windows). It ain't quick but it's flexible, here's the basic command. People have written various cmdlets and scripts for it if you need better formatting.

PS C:\Users\Troll> Compare-Object (gc $file1) (gc $file2)

Not part of Windows, but if you are a developer with Visual Studio, it comes with WinDiff (graphical)

But my personal favorite is BeyondCompare, which costs $30.


If you have installed git on your machine, you can open a git terminal and just use the Linux diff command as normal.


Examples related to windows

"Permission Denied" trying to run Python on Windows 10 A fatal error occurred while creating a TLS client credential. The internal error state is 10013 How to install OpenJDK 11 on Windows? I can't install pyaudio on Windows? How to solve "error: Microsoft Visual C++ 14.0 is required."? git clone: Authentication failed for <URL> How to avoid the "Windows Defender SmartScreen prevented an unrecognized app from starting warning" XCOPY: Overwrite all without prompt in BATCH Laravel 5 show ErrorException file_put_contents failed to open stream: No such file or directory how to open Jupyter notebook in chrome on windows Tensorflow import error: No module named 'tensorflow'

Examples related to cmd

'ls' is not recognized as an internal or external command, operable program or batch file '' is not recognized as an internal or external command, operable program or batch file XCOPY: Overwrite all without prompt in BATCH VSCode Change Default Terminal How to install pandas from pip on windows cmd? 'ls' in CMD on Windows is not recognized Command to run a .bat file VMware Workstation and Device/Credential Guard are not compatible How do I kill the process currently using a port on localhost in Windows? how to run python files in windows command prompt?

Examples related to diff

Create patch or diff file from git repository and apply it to another different git repository Comparing the contents of two files in Sublime Text Git diff between current branch and master but not including unmerged master commits Fast way of finding lines in one file that are not in another? Python - difference between two strings How to see the changes in a Git commit? unix diff side-to-side results? Find the files existing in one directory but not in the other git diff between two different files How to get the difference (only additions) between two files in linux