简体   繁体   中英

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?

Run this in the CMD shell or batch file:

FC file1 file2

FC can also be used to compare binary files:

FC /B file1 file2

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!

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.

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

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 ie just one line ####09

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.

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

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

To my knowledge there are no built-in equivalents.

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

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

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/

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.

如果您已经在计算机上安装了git,则可以打开git终端,然后照常使用Linux diff命令。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM