How to Compare Two Files in Windows 11 Command Line Using the fc Command

When reviewing software source code, system configuration scripts, or plain text documents in Windows 11, developers and system administrators often need to determine whether two files are identical or where their contents diverge. While graphical diff tools exist, Windows includes a fast, native command-line utility called fc (File Compare). Available in both Command Prompt and Windows PowerShell, the fc utility allows you to inspect ASCII text files line by line or examine binary executables byte by byte without installing third-party utilities.

What Is the fc Command in Windows 11?

The fc utility compares two files or sets of files and outputs the discrepancies directly to the terminal. Unlike complex diff engines that require custom installations, fc.exe is built directly into the Windows operating system under C:\Windows\System32\fc.exe. It supports two primary comparison modes:

  • ASCII Comparison (Default): Reads text files line by line, identifies mismatched blocks of text, and finds subsequent matching lines to resynchronise the comparison.
  • Binary Comparison: Compares two files byte by byte, displaying the hexadecimal offset address and the differing byte values between the files.

Basic Syntax of the fc Command

The standard syntax for the fc utility is structured as follows:

fc [options] <path_to_file1> <path_to_file2>

If you run the command inside PowerShell, remember that PowerShell provides an alias fc that points directly to Format-Custom. To invoke the actual Windows File Compare utility inside PowerShell, execute fc.exe instead of fc.

How to Compare Two Text Files Line by Line

To compare two text documents, configuration scripts, or log files, pass their paths directly to the command:

fc config_v1.txt config_v2.txt

When differences exist, the command outputs the name of the first file, the divergent lines, and the first synchronising line that matches in both files. It then outputs the corresponding lines from the second file. If both files are identical, the utility outputs:

FC: no differences encountered

Useful Options and Flags for ASCII Comparison

You can customise how the fc command evaluates text files using several built-in parameters:

1. Case-Insensitive Comparison (/C)

By default, fc treats uppercase and lowercase characters as distinct. If you want to disregard letter casing during the comparison, add the /c switch:

fc /c script1.bat script2.bat

2. Displaying Line Numbers (/N)

To easily locate differences in large source files, use the /n flag. This prepends line numbers to every line displayed in the comparison output:

fc /n server_config.ini server_config_backup.ini

3. Ignoring Whitespace Differences (/W)

If files differ only by indentation spacing or consecutive tabs and blank characters, the /w switch compresses whitespace into single spaces and ignores trailing spaces:

fc /w /n index.html index_updated.html

4. Setting the Resynchronisation Buffer (/LBn)

The /lbn switch sets the maximum number of consecutive lines that fc can read before giving up on resynchronising mismatched text blocks. By default, this buffer is set to 100 lines. For heavily modified documents, increase the threshold:

fc /lb200 file1.txt file2.txt

How to Perform a Binary Comparison (/B)

When comparing compiled binaries, images, archive archives, or database snapshots, an ASCII comparison will fail due to null bytes and control characters. Use the /b flag to trigger a byte-level binary comparison:

fc /b firmware_rev1.bin firmware_rev2.bin

The output lists each mismatched byte showing the file offset followed by the byte values from each file in hexadecimal format:

000001A4: 4D 5A
000001A5: 90 00

Interpreting Exit Codes in Automation Scripts

When automating verification workflows in batch scripts or PowerShell, the fc.exe command returns standardised exit codes that you can evaluate via %ERRORLEVEL% in Command Prompt or $LASTEXITCODE in PowerShell:

  • 0: Both files are completely identical.
  • 1: Differences were detected between the two files.
  • 2: A syntax error occurred, or one or both files could not be located.

For example, in a batch script:

fc fileA.txt fileB.txt > nul
if %ERRORLEVEL% equ 0 (
    echo Files match perfectly.
) else (
    echo Discrepancies detected.
)

Get the best tech tips delivered straight to your inbox.

Join thousands of readers mastering Apple, Google, Microsoft, and Linux.