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.
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.
Before continue to file comparison. we should have two files to compare. and we should know exactly the path of that file to access.
3
Type FC Command.
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.
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]
Switches | Description |
---|---|
/b | If you need to perform binary comparison. use this switch. |
/c | If you need to do a Case insensitive comparison, use this switch. |
/a | If you want to see only the first and last lines for each group of difference. then use this switch. |
/u | If You want to compare files as Unicode text files. then use this switch. |
/l | If you want to compare files as ASCII text. use this switch. |
/n | This switch can only be used with ASCII, but it will show all the corresponding line. |
/t | This 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 |
/lbn | Replace 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. |