What is the Windows equivalent of the diff command

2020-01-25 12:20发布

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?

标签: windows cmd diff
13条回答
三岁会撩人
2楼-- · 2020-01-25 12:55

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
查看更多
姐就是有狂的资本
3楼-- · 2020-01-25 12:55

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!

查看更多
Ridiculous、
4楼-- · 2020-01-25 12:55

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

查看更多
甜甜的少女心
5楼-- · 2020-01-25 12:56

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

查看更多
别忘想泡老子
6楼-- · 2020-01-25 12:59

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

查看更多
Rolldiameter
7楼-- · 2020-01-25 13:03

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/

查看更多
登录 后发表回答