Topic : How to compare two file using CMD?



How to compare two file using Command prompt?

Command prompt is a great command line tool to compare two files to see if there are any content or binary code differences. We can compare the contents of text or binary files and is capable of comparing both ASCII and Unicode text. we can use the command line to display any lines from two files or two sets of files that do not match up with the others.

Follow the given steps to compare the files and enjoy your learning with infoBrother.




»

QUICK SUMMARY:



1

Open command prompt.


File compare using CMD - Step No 1 : InfoBrother

We can open command prompt or CMD using two ways:
1 » Click the window icon or press window key. search for cmd or command prompt and run it as Administration.
2 » Press Window key + R , A dialog box will open, type cmd in text area to open the command prompt. type cmd and press enter.




2

Get the File Path.


File compare using CMD - Step No 2 : InfoBrother

Before continue to file comparison. we should have two files to compare. and we should know exactly the path of that file to access.


Tip:To get the exact file path. just open the folder where your file located. click at the top address bar and the path will be high lighted. copy the file path into your clip board and use it.



3

Type FC Command.


File compare using CMD - Step No 3 : InfoBrother

Now we have two files to be compare. Now In Our Console window, that we open using cmd command. we need to type following command.


fc [filepath1] [filepath2] 

replace the complete path (that we noted in step 2) of both file with Filepath1 and filepath2 without braces. as shown in the the above picture and hit enter. if both files are same, mean nothing difference between the content of both files than the FC command will return the message "no differences encountered" as shown in above picture.



File compare using CMD - Step No 4 : InfoBrother

And if there is any difference in these files. Even if a small difference, The FC Command will display all the contents of both files.




4

Parameters to compare files.

WE CAN USE SOME PARAMETERS TO COMPARE THE FILES IN DIFFERENT CONDITION.

We can use some switches and parameters to compare the files in some different condition. or as we want to compare. here is the list and short definition of those parameters. and the syntax for the command along with switches will be:


fc [switches] [file1] [file2]

SwitchesDescription
/bIf you need to perform binary comparison. use this switch.
/cIf you need to do a Case insensitive comparison, use this switch.
/aIf you want to see only the first and last lines for each group of difference. then use this switch.
/uIf You want to compare files as Unicode text files. then use this switch.
/lIf you want to compare files as ASCII text. use this switch.
/nThis switch can only be used with ASCII, but it will show all the corresponding line.
/tThis switch will tell FC to don't expand tabs to spaces.
/w If you want to compress white space (tabs and spaces) during comparison. use this switch
/lbnReplace the "n" with the number, to limit the amount of consecutive different lines that FC will read before it will abort. Example: /lb2: This command will tell fc to stop after 2 lines of mismatched data.


You like it? Other May like it too:

PLEASE SHARE









I Tried my Best to Provide you complete Information regarding this topic in very easy and conceptual way. but still if you have any Problem to understand this topic, or do you have any Questions, Feel Free to Ask Question. i'll do my best to Provide you what you need.

Sardar Omar.
InfoBrother