如何在 Windows Cmd Prompt 中执行 UNIX 的“diff -r”?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1011269/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 06:30:24  来源:igfitidea点击:

How to do "diff -r" of UNIX in Windows Cmd Prompt?

windowscmd

提问by

How do I compare two directories on cmd prompt of Windows m/c? I want equivalent of diff -r of UNIX.

如何在 Windows m/c 的 cmd 提示符下比较两个目录?我想要相当于 UNIX 的 diff -r 。

回答by RichieHindle

Install Cygwinand you can use diff -ron Windows.

安装Cygwin就可以diff -r在 Windows 上使用了。

回答by victor hugo

The compcommand for Windows is what you're looking for.

适用于 Windows的comp命令正是您要寻找的。

Here the example:

这里的例子:

To compare the contents of the directory C:\Reports with the backup directory \\Sales\Backup\April, type:

要将目录 C:\Reports 的内容与备份目录 \\Sales\Backup\April 进行比较,请键入:

comp c:\reports \sales\backup\april 

回答by carlpett

The easiest way would probably be downloading diff for Windows: http://gnuwin32.sourceforge.net/packages/diffutils.htm
You could also do something like:

最简单的方法可能是为 Windows 下载 diff:http: //gnuwin32.sourceforge.net/packages/diffutils.htm
您也可以执行以下操作:

dir directory1 > dir1
dir directory2 > dir2
comp dir1 dir2

Also, some versions of Windows comes with windiff, however that is a GUI tool

此外,某些版本的 Windows 带有windiff,但这是一个 GUI 工具

回答by Adri C.S.

In Windows there is the fccommand. I think diffis way better, but if you want to use only what came with the installation, well, here you go! :)

在 Windows 中有fc命令。我认为diff这样更好,但如果您只想使用安装附带的内容,那么,就这样吧!:)

回答by Victor

You can install Gow, and you can run diff in the Windows Command Prompt.

您可以安装 Gow,并且可以在 Windows 命令提示符中运行 diff。

回答by Ivan Suhinin

You can use windiff util included in Windows from NT version and up. Just run 'windiff' and a graphic tool will pop up.

您可以使用 Windows NT 及更高版本中包含的windiff util。只需运行“winddiff”,就会弹出一个图形工具。

File -> Compare directories

文件 -> 比较目录

http://msdn.microsoft.com/en-us/library/aa266122(VS.60).aspx

http://msdn.microsoft.com/en-us/library/aa266122(VS.60).aspx

This article describes how to use it from command line. Great benefit of this tool is that it is already included and you don't need to download and install anything.

本文介绍如何从命令行使用它。这个工具的一大好处是它已经包含在内,你不需要下载和安装任何东西。

回答by Hari

To compare data with command prompt you can use

要将数据与命令提示符进行比较,您可以使用

COMP /a /l D:\Folder1\data.txt D:\Folder2\data.txt

COMP /a /l D:\Folder1\data.txt D:\Folder2\data.txt

There can be different options like specific numbers of lines to search and case insensitive search and even you can compare folders with command prompt. Here are other options to compare files and folders with command prompt.

可以有不同的选项,例如要搜索的特定行数和不区分大小写的搜索,甚至您可以将文件夹与命令提示符进行比较。以下是通过命令提示符比较文件和文件夹的其他选项。

回答by akavel

Partial solution with ROBOCOPY

ROBOCOPY 的部分解决方案

A partial solution (and thus for me unfortunately a "non-solution", although I had high hopes for it initially), which may or may not be enough for you:

部分解决方案(因此对我来说不幸的是“非解决方案”,尽管我最初对它寄予厚望),这对您来说可能还不够:

It seems the ROBOCOPY tool can be (ab-)used to work as a kinda poor man's recursive comparison; with the unfortunate limitation, that it apparently doesn't compare file contents. It seems to compare sizes, datesand optionally attributes. The magic incantation for this would be:

似乎ROBOCOPY 工具可以(ab-)用作一个有点可怜的人的递归比较;不幸的是,它显然没有比较文件内容。它似乎比较大小、日期和可选的属性。对此的魔法咒语是:

ROBOCOPY path1 path2 /e /l /ns /njs /njh /ndl /fp /log:result.txt /it

where optionsmeaningseems to be:

其中选项的意思似乎是:

  • /e- recurse, including empty directories;
  • /l- only print a log, don't modify files;
  • /ns /njs /njh- don't print file sizes, job summary, job header;
  • /ndl- "don't log folder names"
    • NOTE: this reportedly will result in skipping cases of missing/superfluous empty dirs; if you don't use this, those should get logged, but you'll have to somehow remove non-differing dirs by other means;
  • /log:result.txt- write results to 'result.txt' file; I think this can be omitted and result will be shown on standard output then.
  • /e- 递归,包括空目录;
  • /l-只打印日志,不修改文件;
  • /ns /njs /njh- 不打印文件大小、作业摘要、作业标题;
  • /ndl- “不记录文件夹名称”
    • 注意:据报道,这将导致跳过丢失/多余的空目录的情况;如果你不使用它,那些应该被记录,但你必须以某种方式通过其他方式删除非不同的目录;
  • /log:result.txt- 将结果写入“result.txt”文件;我认为这可以省略,然后结果将显示在标准输出上。

Additional options:

其他选项:

Warning: does NOT compare file contents

警告:不比较文件内容

As I said above, this seems not to compare file contents, unfortunately. I verified this by running the following command first:

正如我上面所说,不幸的是,这似乎不是比较文件内容。我首先通过运行以下命令来验证这一点:

mkdir d1\a\b d2\a\b & echo x > d1\a\b\f & echo y > d2\a\b\f

Most of the time, this should produce files d1\a\b\f and d2\a\b\f with same timestamps, you can verify with dir d1\a\b\f d2\a\b\f. The robocopycall on d1 & d2 produced an empty result set for me.

大多数情况下,这应该生成具有相同时间戳的文件 d1\a\b\f 和 d2\a\b\f,您可以使用dir d1\a\b\f d2\a\b\f. robocopy对 d1 和 d2的调用为我生成了一个空结果集。

回答by krpra

In Windows 10 you can run diffcommand in bashby Enabling the Linux Bash Shell

在 Windows 10 中,您可以通过启用 Linux Bash Shell来运行diff命令bash