OPERATING SYSTEMSOS Windows

How to compare two Files for changes using Command Prompt


If you are searching for a way to compare two files on Windows 10/11 without any third-party program, we have a way for you. In this guide, we show you how you can compare two files for changes with Command Prompt on Windows 10/11.

You can compare two files using the fc.exe and the comp.exe file compare commands. You can use fc.exe to compare two ASCII or binary files on a line-by-line basis. windiff.exe utility, a tool that graphically compares the contents of two ASCII files, or the contents of two folders that contain ASCII files, to verify whether they are the same.

How to compare two Files for changes using Command Prompt on Windows 11/10

If you want to find how two similar files have undergone changes over time, there is a built-in command on Windows that lets you compare. That command is fc. This command is useful in comparing two text files and know how they are changed in its script and its modifications. With ‘fc‘ command, you can compare a text file with its latest version or find changes at the script level in different scripts like Binary, Unicode, or ASCII. Let’s see how we can use ‘fc’ command and compare two Files for changes With Command Prompt on Windows 10/11.

Compare two Files for Changes using FC.exe command-line

There are different parameters in fc command which you can use it to achieve different result after entering the syntax in Command Prompt.

Parameters

Meaning

/a The parameter displays only the first and last line for each set of differences
/b

Compares the two files in binary mode, byte by byte, and does not attempt to resynchronize the files after finding a mismatch. 

/c

Ignores the letter case.

/l

Compares the files in ASCII mode, line-by-line, and attempts to resynchronize the files after finding a mismatch.

/lb<n>

Sets the number of lines for the internal line buffer to N. The default length of the line buffer is 100 lines. If the files that you are comparing have more than 100 consecutive differing lines, fc cancels the comparison.

/n

Displays the line numbers during an ASCII comparison.

/off[line] Doesn’t skip files that have the offline attribute set.
/t

Prevents fc from converting tabs to spaces.

/u

Compares files as Unicode text files.

/w

Compresses 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 /wfc ignores white space at the beginning and end of a line.

/<nnnn>

Specifies the number of consecutive lines that must match following a mismatch, before fc considers the files to be resynchronized. 

[<drive1>:]

[<path1>]

<filename1>

Specifies the location and name of the first file or set of files to compare. filename1 is required.

[<drive2>:]

[<path2>]

<filename2>

Specifies the location and name of the second file or set of files to compare. filename2 is required.

/?

Displays help at the command prompt.

Usage of the fc command

How do I compare two files in Windows?

You can use fc command to compare two text files for changes or use the windiff.exe utility that comes with the Windows installation. The tool helps you graphically compare the contents of two ASCII files, or the contents of two folders that contain ASCII files, to verify if they are the same or not. You can also compare two text files in Windows using fc command. It has different parameters to do different types of comparisons.

1] If you want to compare two files names June and July in ASCII format and display the result in an abbreviated format, you can use:

fc /a june.rpt july.rpt

2] If you want to make a binary comparison of two bat files named June and July, use the following syntax:

fc /b june.bat july.bat

3] If you want to compare every bat file in a directory with July.bat file, use the following syntax:

fc *.bat july.bat

4] If you want to compare July.bat file on C drive with July.bat file on D drive, you can use:

fc c:july.bat d:*.bat

5] If you want to compare each batch file in the root directory on drive C to the file with the same name in the root directory on drive D, you can use:

fc c:*.bat d:*.bat

These are some of the commonly usable syntax using fc command in Command Prompt. You need to understand the parameters perfectly and write your own syntax if you have special requirements. Microsoft has some detailed explanations of some regularly used fc commands.

Related Read: Useful Commands to Manage Files and Folders using Command Prompt.

Compare Two Files for Changes With Command Prompt

Source link

Leave a Reply

Your email address will not be published. Required fields are marked *