博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
如何从Windows命令提示符下使用FC(文件比较)
阅读量:2518 次
发布时间:2019-05-11

本文共 8811 字,大约阅读时间需要 29 分钟。

FC 0

There is a great command line tool that can be used to compare files to see if there are any content or binary code differences that you can access if you are using a PC. File Compare or FC as we will refer to is from here on out, is a simple program that will compare the contents of text or binary files and is capable of comparing both ASCII and Unicode text. You can use this tool to display any lines from two files or two sets of files that do not match up with the others.

有一个很棒的命令行工具,可以用来比较文件,以查看是否存在使用PC时可以访问的内容或二进制代码差异。 从这里开始,我们将要提到的File Compare或FC是一个简单的程序,它将比较文本或二进制文件的内容,并且能够比较ASCII和Unicode文本。 您可以使用此工具显示两个文件或两组文件中与其他文件不匹配的任何行。

文件比较的开关和参数 (File Compare’s Switches and Parameters)

  1. /B – This switch will perform a binary comparison.

    / B –此开关将执行二进制比较。

  2. /C – If you need to do a case insensitive comparison, use this switch.

    / C –如果需要进行不区分大小写的比较,请使用此开关。

  3. /A – This switch will make FC show only the first and last lines for each group of differences.

    / A –此开关将使FC仅显示每组差异的第一行和最后一行。

  4. /U – Use this switch to compare files as Unicode text files.

    / U –使用此开关将文件比较为Unicode文本文件。

  5. /L – This will compare your files as ASCII text.

    / L –这会将您的文件比较为ASCII文本。

  6. /N – This switch can only be used with ASCII but it will show all the corresponding line numbers.

    / N –此开关只能与ASCII一起使用,但是它将显示所有相应的行号。

  7. /LBn – Replace the “n” with a number to limit the amount of consecutive different lines that FC will read before it will abort. The default, if you do not specify a number is 100 lines of mismatched text.

    / LB n –用数字替换“ n”以限制FC在终止之前将读取的连续不同行的数量。 如果未指定数字,则默认值为100行不匹配的文本。

  8. /nnnn – Replacing the “n’s” here will tell FC that when it finds mismatched lines, it can only continue if it finds “n” consecutive matching lines after the mismatch. This is useful if you want to prevent two files from becoming extremely out of sync.

    / nnnn –在此处替换“ n”将告诉FC,当发现不匹配的行时,只有在不匹配之后找到“ n”个连续匹配的行时,它才能继续。 如果要防止两个文件变得极不同步,这很有用。

  9. /T – This switch will tell FC not to expand tabs to spaces.

    / T –此开关将告诉FC不要将制表符扩展到空格。

  10. /W – If you use this switch, FC will compress white space (tabs and spaces) during its comparison of your files.

    / W –如果使用此开关,FC将在比较文件时压缩空白(制表符和空格)。

There is only one parameter you will need to specify, but you will need to enter two instances of it. This is the Pathname parameter in which you will state the location of your files.

您仅需要指定一个参数,但是您需要输入该参数的两个实例。 这是Pathname参数,在其中您将说明文件的位置。

FC的语法 (FC’s Syntax)

Like every tool in command prompt, you will need to know how to enter your commands with the proper syntax. There are two main options for the File Compare tool that you can use. If you want to compare two sets of files instead of two individual files, you can use wildcards (? and *).

像命令提示符中的每个工具一样,您将需要知道如何以正确的语法输入命令。 您可以使用文件比较工具的两个主要选项。 如果要比较两组文件而不是两个单独的文件,则可以使用通配符(?和*)。

FC [pathname1] [pathname2]
FC [pathname1] [pathname2]
FC [switches] [pathname1] [pathname2]

Depending on your command, you will receive one of four %errorlevel% responses.

根据您的命令,您将收到四个%errorlevel%响应之一。

  1. -1 – Your syntax is incorrect.

    -1 –您的语法不正确。
  2. 0 – Both files are identical.

    0 –两个文件相同。
  3. 1 – The files are different.

    1 –文件不同。
  4. 2 – At least one of the files can’t be found.

    2 –至少找不到一个文件。

让我们练习 (Let’s Practice)

Before we get started, you should download our three sample text documents which we will use for the test. These documents each contain a paragraph of text with a few similar word groupings. Once you have downloaded these three documents, you can copy them into any folder on your computer. For the purposes of this tutorial, we will put all the text documents on the desktop.

在开始之前,您应该下载我们的三个样本文本文档,我们将用于测试。 这些文档每个都包含一段文本,并带有一些相似的词组。 下载这三个文档后,可以将它们复制到计算机上的任何文件夹中。 在本教程中,我们将所有文本文档放在桌面上。

Now you will need to open up an elevated command prompt window. Open the start menu in Windows 7 and 10 or open the search function in Windows 8 and search for CMD. Next, right-click on it and then press “Run as administrator.” While you don’t need to open an elevated command prompt window, it will help you to avoid any pesky confirmation dialog boxes.

现在,您将需要打开提升的命令提示符窗口。 在Windows 7和10中打开开始菜单,或在Windows 8中打开搜索功能并搜索CMD。 接下来,右键单击它,然后按“以管理员身份运行”。 虽然您不需要打开提升的命令提示符窗口,但它将帮助您避免出现任何讨厌的确认对话框。

sshot-1

Our tutorial today will cover several simple scenarios which will be elaborated on below.

我们今天的教程将涵盖以下几个简单的场景。

  1. Compare two text files in the same folder using File Compare.

    使用文件比较比较同一文件夹中的两个文本文件。
  2. Compare files in the same folder using File Compare using the “/lbn” switch.

    使用“ / lbn”开关使用“文件比较”比较同一文件夹中的文件。
  3. Compare two identical files.

    比较两个相同的文件。
  4. Perform a binary comparison of two different files and two identical files.

    对两个不同的文件和两个相同的文件执行二进制比较。

Scenario 1 – Compare two text files using File Compare.

方案1 –使用“文件比较”比较两个文本文件。

Now that you have your command prompt window open and you have your text files on your desktop, we are ready to do a simple file comparison. In this section, we will do a basic comparison, and then add a few different options. Begin by entering the following command to compare the contents of “FCsample” and “FCexercise.” Remember to substitute the pathname with the name that matches your computer, and remember that command prompt is not case sensitive.

现在您已经打开了命令提示符窗口,并且在桌面上拥有了文本文件,我们准备进行简单的文件比较。 在本节中,我们将进行基本比较,然后添加一些不同的选项。 首先输入以下命令比较“ FCsample”和“ FCexercise”的内容。 请记住用与您的计算机匹配的名称替换路径名,并记住命令提示符不区分大小写。

fc C:\Users\Martin\Desktop\FCsample.txt C:\Users\Martin\Desktop\FCexercise.txt
fc C:\Users\Martin\Desktop\FCsample.txt C:\Users\Martin\Desktop\FCexercise.txt
FC 2

In this case, all the text from both documents is shown because they do not match up properly.

在这种情况下,将显示两个文档中的所有文本,因为它们不正确匹配。

Scenario 2 – Compare files in the same folder using File Compare using the “/lbn” switch.

方案2 –使用“ / lbn”开关使用“文件比较”比较同一文件夹中的文件。

Now, let’s try another comparison in which we will tell FC to stop after 2 lines of mismatched data. Do this, by adding the “/lbn” switch.

现在,让我们尝试另一个比较,在此比较中,我们将告诉FC在两行数据不匹配后停止。 通过添加“ / lbn”开关来执行此操作。

fc /lb2 C:\Users\Martin\Desktop\FCsample.txt C:\Users\Martin\Desktop\FCexercise.txt
FC 3

As you can see, you receive an error message which says “Resync Failed. Files are too different.” This is because there are more than two consecutive lines of mismatched data. Try changing the numbers or editing the files yourself and play with the file compare tool to see what results you get.

如您所见,您收到一条错误消息,提示“重新同步失败。 文件太不同了。” 这是因为存在多于两个连续的不匹配数据行。 尝试自己更改数字或编辑文件,然后使用文件比较工具查看获得的结果。

Scenario 3 – Compare two identical files.

方案3 –比较两个相同的文件。

In the files you downloaded, you will see two files called “FCexercise” and “FCexercise2.” These two files have exactly the same content, so we will perform a comparison and see what results we get.

在下载的文件中,您将看到两个名为“ FCexercise”和“ FCexercise2”的文件。 这两个文件的内容完全相同,因此我们将进行比较并查看得到的结果。

fc C:\Users\Martin\Desktop\ FCexercise.txt C:\Users\Martin\Desktop\FCexercise2.txt
fc C:\Users\Martin\Desktop\ FCexercise.txt C:\Users\Martin\Desktop\FCexercise2.txt
FC 4

As you can see from the image above, FC reports that no differences were encountered. If you were to edit one file, add a single letter, and try the command again, your results would show up as in the image below. Note that the only thing that was changed was the addition of the letter “a.”

从上图可以看到,FC报告没有遇到任何差异。 如果要编辑一个文件,添加一个字母,然后再次尝试命令,结果将显示在下图中。 请注意,唯一更改的是字母“ a”的添加。

FC 5

Scenario 4 – Perform a binary comparison of two different files and two identical files.

方案4 –对两个不同的文件和两个相同的文件执行二进制比较。

For this example, we will be performing a binary comparison of the “FCexercise” and “FCsample” files.

对于此示例,我们将对“ FCexercise”和“ FCsample”文件进行二进制比较。

fc /b C:\Users\Martin\Desktop\ FCexercise.txt C:\Users\Martin\Desktop\sample.txt
FC 6
FC 7

You will notice that the function begins by informing you that the two files are being compared. Next, a bunch of binary digits scroll by, which is where the files are being compared, side by side, and lastly, you receive a report that says that, FCexercise is longer than FCsample.  For this next example, we will be performing a binary comparison of the “FCexercise” and “FCexercise2” files.

您会注意到,该功能首先通知您正在比较两个文件。 接下来,一串二进制数字并排滚动,这是文件并排比较的地方,最后,您收到一个报告,说FCexercise比FCsample长。 对于下一个示例,我们将对“ FCexercise”和“ FCexercise2”文件进行二进制比较。

fc /b C:\Users\Martin\Desktop\ FCexercise.txt C:\Users\Martin\Desktop\FCexercise2.txt
fc /b C:\Users\Martin\Desktop\ FCexercise.txt C:\Users\Martin\Desktop\FCexercise2.txt
FC 8

In this comparison of two identical files, FC reports that there is no difference between the two files. Now that you know the basics of the FC tool, feel free to play with the switches and test out some new ideas. Remember that while you are playing with files, it is best to use dummy samples like the ones provided here, in order to avoid any accidental data loss.

在两个相同文件的比较中,FC报告两个文件之间没有差异。 现在,您已经了解了FC工具的基础知识,可以随意使用这些开关并测试一些新想法。 请记住,在播放文件时,最好使用虚拟样本(如此处提供的样本),以避免任何意外的数据丢失。

Image Credit: on Flickr

图片来源:Flickr上的

翻译自:

转载地址:http://itawd.baihongyu.com/

你可能感兴趣的文章
ATMEGA16 IOport相关汇总
查看>>
JAVA基础-多线程
查看>>
面试题5:字符串替换空格
查看>>
[Codevs] 线段树练习5
查看>>
Amazon
查看>>
component-based scene model
查看>>
Echart输出图形
查看>>
hMailServer搭建简单邮件系统
查看>>
从零开始学习jQuery
查看>>
Spring+SpringMVC+MyBatis深入学习及搭建(四)——MyBatis输入映射与输出映射
查看>>
opacity半透明兼容ie8。。。。ie8半透明
查看>>
CDOJ_24 八球胜负
查看>>
Alpha 冲刺 (7/10)
查看>>
一款jQuery打造的具有多功能切换的幻灯片特效
查看>>
SNMP从入门到开发:进阶篇
查看>>
@ServletComponentScan ,@ComponentScan,@Configuration 解析
查看>>
unity3d 射弹基础案例代码分析
查看>>
thinksns 分页数据
查看>>
os模块
查看>>
LINQ to SQL vs. NHibernate
查看>>