Windows cmd сравнение файлов

Windows 11 FC command to compare files

(Image credit: Mauro Huculak)

On Windows 11 (and 10), the File Compare (fc) is a command-line tool that comes part of the system, and it allows you to compare two similar files to determine how they changed over time. Usually, «fc» will be helpful for comparing simple text files, determining the changes made to a script, detecting if a file has been modified, and similar scenarios.

The tool can compare two similar files or the newest version against all the other files in the same location. Also, it includes options to examine the changes at the text level, or in Unicode, ASCII, or binary mode.

In this how-to guide, you will learn steps to use the tool to compare files with Command Prompt on Windows 11 as well as on Windows 10.

Recent updates

This guide has been updated to ensure the instructions are still accurate and reflect you can also use the tool on Windows 11.

How to compare files with the fc command on Windows 11

To compare files with the fc command tool, use these steps:

  1. Open Start.
  2. Search for Command Prompt, right-click the top result, and select the Run as administrator option.
  3. Type the following command to browse to the folder with the files you want to compare and press Enter: cd PATH\TO\FILES

In the command, update the path with the location of the folder with the files to compare. This example navigates to the Downloads folder: cd C:\Users\USERACCOUNT\Downloads

  1. Type the following command to compare two similar files and press Enter: fc filename1.txt filename2.txt

In the command, replace filename1.txt and filename2.txt for the name of the files you want to compare.

fc compare files command

(Image credit: Mauro Huculak)
  1. Type the following command to compare two similar files in ASCII mode and press Enter: fc /L filename1.txt filename2.txt
  2. Type the following command to compare two files displaying only the first line that is different and press Enter: fc /a filename1.txt filename2.txt

fc compare two files showing first line

(Image credit: Mauro Huculak)
  1. Type the following command to compare two files in Unicode mode and press Enter: fc /u filename1.txt filename2.txt

fc compare two files in Unicode mode

(Image credit: Mauro Huculak)
  1. Type the following command to compare two files in binary mode and press Enter: fc /b filename1.txt filename2.txt

fc compare two files in binary mode

(Image credit: Mauro Huculak)
  1. Type the following command to compare all the files (*.txt) in the same folder to the new file (filename2.txt) and press Enter: fc *.txt filename2.txt

fc compare multiple files

(Image credit: Mauro Huculak)
  1. Type the following command to compare two files in different locations and press Enter: fc DRIVE:\PATH\TO\filename1.txt DRIVE:\PATH\TO\filename2.txt

In the command, replace DRIVE for the storage location drive letter and \PATH\TO\filename1.txt and \PATH\TO\filename2.txt with the path and name of the files you want to compare.This example compares two files in different folders: fc C:\Users\USERACCOUNT\Downloads\filename1.txt C:\Users\USERACCOUNT\Downloads\new\filename2.txt

All the latest news, reviews, and guides for Windows and Xbox diehards.

fc compare two files in different location

(Image credit: Mauro Huculak)
  1. Confirm the output to see the difference between the files.
  • Quick tip: You can view the list of options and more examples using the fc /? command.

Once you complete the steps, you will be able to see the difference between two similar files.

While the tool allows you to compare files, remember that this is a basic tool meant to be used with text files and extensions like .exe, .com, .sys, .obj, .lib, or .bin. You may be able to compare files like those from Microsoft Office or images, but you can only compare them at the binary level.

More resources

For more in-depth insights, troubleshooting tips, and the latest updates on Windows 11 and 10, be sure to explore these resources:

  • Windows 11 on Windows Central — All you need to know
  • Windows 10 on Windows Central — All you need to know

Mauro Huculak has been a Windows How-To Expert contributor for WindowsCentral.com for nearly a decade and has over 15 years of experience writing comprehensive guides. He also has an IT background and has achieved different professional certifications from Microsoft, Cisco, VMware, and CompTIA. He has been recognized as a Microsoft MVP for many years.

Для сравнения содержимого файлов в командной строке Windows есть специальная утилита fc. Утилита позволяет сравнить содержимое двух или группы файлов и отобразить найденные различия.

fc /?

cmd

  • /A — вывод только первой и последней строк для каждой группы различий.
  • /B — сравнение двоичных данных.
  • /C — не учитывать регистр символов.
  • /L — сравнение файлов в формате ASCI.
  • /Lbn — максимальное число несоответствий для заданного числа строк.
  • /N — вывод номеров строк.
  • OFF[LINE] — не пропускать файлы с атрибутом «Автономный».
  • /T — не заменять табуляцию пробелами.
  • /U — сравнение файлов в формате UNICODE.
  • /W — пропускать пробелы и табуляцию.
  • /nnnn — число последовательных совпадающих строк, которое должно встретиться после группы несовпадающих.
  • [drive1:][path1]filename1 — первый файл или набор файлов для сравнения.
  • [drive2:][path2]filename2 — второй файл или набор файлов для сравнения.

Сравним два XML файла без учёта пробелов, табуляции, регистра. Дополнительно выведем номера строк.

fc /C /W /N "filepath1" "filepath2"

fc

Первой выводится строка, идущая перед найденным отличием.

Quick Links

  • File Compare’s Switches and Parameters

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.

File Compare’s Switches and Parameters

  1. /B – This switch will perform a binary comparison.
  2. /C – If you need to do a case insensitive comparison, use this switch.
  3. /A – This switch will make FC show only the first and last lines for each group of differences.
  4. /U – Use this switch to compare files as Unicode text files.
  5. /L – This will compare your files as ASCII text.
  6. /N – This switch can only be used with ASCII but it will show all the corresponding line numbers.
  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.
  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.
  9. /T – This switch will tell FC not to expand tabs to spaces.
  10. /W – If you use this switch, FC will compress white space (tabs and spaces) during its comparison of your files.

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.

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 [switches] [pathname1] [pathname2]

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

  1. -1 – Your syntax is incorrect.
  2. 0 – Both files are identical.
  3. 1 – The files are different.
  4. 2 – At least one of the files can’t be found.

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.

  1. FCsample
  2. FCexercise
  3. FCexercise2

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.

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.
  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.

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.

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.

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 /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.

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.

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 5

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

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

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.

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.

Image Credit: Nikki on Flickr

  • SS64
  • CMD
  • How-to

FC.exe

Compare the contents of two files or sets of files. Display any lines which do NOT match.

Syntax
      FC [options] [drive1:][path1] filename1 [drive2:][path2] filename2

Options
   /A    Abbreviate the output of an ASCII comparison, display only first and last lines
         for each set of differences.

   /B    Perform a binary comparison. FC compares the two files byte by byte and does not attempt
         to resynchronize the files after finding a mismatch.
         This is the default mode for comparing files that have the following file extensions:
          .exe, .com, .sys, .obj, .lib, or .bin. 

   /C    Do a case insensitive string comparison

   /L    Compare the files in ASCII mode. Fc compares the two files line by line and attempts to resynchronize
         the files after finding a mismatch.
         This is the default mode for comparing non binary files, see /B. 

   /LBn  Set the n number of lines for the internal line buffer. The default length of the line buffer is 100 lines.
         If the files being compared have more than this number of consecutive differing lines, FC cancels the comparison. 

   /N    Display line numbers during an ASCII comparison.

   /T    Prevent FC from converting tabs to spaces.
         The default behavior is to treat tabs as spaces, with stops at each eighth character position.

   /U    Compares files as Unicode text files.

   /W    Compress white space (that is, tabs and spaces) during the comparison.
         If a line contains many consecutive spaces or tabs, /w treats these characters as a single space.
         When used with the /W command-line option, FC ignores (and does not compare) white space at the beginning and end of a line. 

   /nnnn   The a number of consecutive lines that must match before FC considers the files to be resynchronized.
           If the number of matching lines in the files is less than nnnn, FC displays the matching lines as differences.
           The default value is 2.

 [ drive1 : ][ path1 ] filename1   The location and name of the first file you want to compare.
                                   Filename1 is required.

 [ drive2 : ][ path2 ] filename2   The location and name of the second file you want to compare.
                                   Filename2 is required.

 Wildcards ( * and ? ) may be used with filename1 or filename2, FC will then compare all the matching files.

PowerShell also has an Alias FC for the Format-Custom cmdlet, therefore to run the ‘old’ FC under PowerShell you can explicitly run C:\windows\system32\fc.exe

Errorlevels

FC will set an ErrorLevel as follows:

-1 Invalid syntax (e.g. only one file passed)
0 The files are identical.
1 The files are different.
2 Cannot find at least one of the files.
For an invalid switch (with two passed files) an error message is printed but the errorlevel is not changed.

The messages returned by FC are language/locale dependent, so to reliably identify 2 identical files use redirection syntax:

   FC File1.txt File2.txt >NUL && Echo Same || Echo Different or error

Comparison order

When FC is used for an ASCII comparison, it will display differences between two files in the following order:

  1. Name of the first file
  2. Lines from filename1 that differ between the files
  3. First line to match in both files
  4. Name of the second file
  5. Lines from filename2 that differ
  6. First line to match

Binary Comparisons

/B displays mismatches found during a binary comparison as follows: xxxxxxxx: yy zz

The value of xxxxxxxx specifies the relative hexadecimal address for the pair of bytes, measured from the beginning of the file. Addresses start at 00000000.
The hexadecimal values for yy and zz represent the mismatched bytes from filename1 and filename2, respectively.

When comparing binary files that are larger than available memory, FC compares both files completely, overlaying the portions in memory with the next portions from the disk.

PowerShell

Like every other external command FC can be run under PowerShell instead of CMD, however there is one extra complication for FC and that is the standard PowerShell alias FC which redirects to the
Format-Custom cmdlet.

To avoid that, use the call operator to run FC.exe:

& fc.exe

Examples

Make a binary comparison of two DLL files:

FC /b new.dll old.dll

Compare two files and report if they are identical:

(FC /B "new.dll" "old.dll" | Find "FC: no differences encountered") > nul && (Echo The Files match.)

Make an ASCII comparison of two text files and display the result in abbreviated format:

FC /a C:\demo\input.txt H:\work\output.txt

# Oh lord won’t you buy me a Mercedes Benz, my friends all drive Porsches, I must make amends # ~ Janice Joplin

Related commands

COMP — Compare two files and display any characters which do NOT match.
FIND — Search for a text string in a file.
FINDSTR — Search for strings in files.
WinDiff — GUI to compare files.
Equivalent PowerShell: Compare-Object — Compare the properties of objects, e.g. compare content of files.
Equivalent bash command (Linux):cmp — Compare two files.


Copyright © 1999-2025 SS64.com
Some rights reserved

Понравилась статья? Поделить с друзьями:
0 0 голоса
Рейтинг статьи
Подписаться
Уведомить о
guest

0 комментариев
Старые
Новые Популярные
Межтекстовые Отзывы
Посмотреть все комментарии
  • Скины для райнметер windows 10
  • Программа для записи с микрофона на компьютер windows 10
  • Как убрать рекламу с панели задач windows 10
  • Как изменить имя пользователя в windows 10 домашняя
  • Windows server 2016 wiki