How to Change File Attributes – (ATTRIB, Windows Command Line, CMD, DOS)
File attributes grant or deny certain rights to every file and folder. The attrib command can be used to view or change file attributes on files or folders.
Welcome!
This guide is all about comparing files directly from the windows command line.
Lets get started!
If you are a programmer or a writer it is very useful to know if there are any differences between two files.
You can use the command line to display any differences using the FC command.
FC stands for file compare and as the name implies it can be used to make binary or text file comparisons on both ASCII and Unicode text.
We are going to learn how to do just that in this short guide.
If you would like to follow along, open your command line and navigate to a directory of your choice (i.e. Desktop) and use the echo command along with a redirector to create two files.
echo Hello > File1.txt & echo Coodbye > File2.txt
Two files should immediately be created in you current directory.
Now that our files have been created lets learn how to compare them using the FC command.
Using the FC command is easy, to compare the files we just created simply type the FC command followed by the names of our files one after the other.
FC File1.txt File2.txt
The FC command will immediately output every line that is different between the two files, allowing you to quickly and efficiently assess any differences.
If the command line was not able to locate your files even tho you are sure they are located in he same directory as the command line, it might have been so because the names of your files contain spaces within their name.
If that’s the case you need to surround the names of your files with quotes.
That’s because the quotes tell the command line that the spaces separating the words do not constitute an additional parameter and are just a continuation of the name of your file.
This is what the command should look like:
FC "File1.txt" "File2.txt"
You can use the FC command to compare files that are located in a different directory than the one you are currently on, by typing their location followed by a backward slash and the name of your file instead of the name of your file directly.
FC "C:\Users\<Username>\Desktop\File1.txt" "C:\Users\<Username>\Desktop\File2.txt"
Replace <Username> with your computers name.
The FC command by default differentiates words based on their casing, meaning, for example, that the words “Awesome” and “awesome” will be deemed different by the FC command because of their casing difference.
If this is not the desired behavior use the /c parameter to make the FC command ignore any such differences.
FC /c "File1.txt" "File2.txt"
So far we have been using the FC command to compare only two files, the FC command can be used to make multiple comparisons with just one command with the use of wildcards.
Wildcards are special symbols that take the place of characters or words.
For example:
FC "*.txt" "File2.txt"
Every text file in the current directory will be compared against “File2.txt”.
As you can see i have enclosed the wildcard in quotes because some of the names of our files in the current directory might contain spaces.
We can even use the FC command to compare every text file in the current directory against one another.
FC "*.txt" "*.txt"
Apart from comparing the text between two files we can use the FC command to perform binary comparisons as well.
To compare the binary data between two files you need to use the FC command along with the /b parameter.
This is what the command should look like.
FC /B "File1.txt" "File2.txt"
View the differences between two files.
FC "File1.txt" "File2.txt"
View the differences between two files that are located in the desktop directory (replace with our computers username).
FC "C:\Users\Desktop\File1.txt" "C:\Users\Desktop\File2.txt"
Compare every text file in the current directory with “File2.txt” while ignoring any casing differences.
FC /c "*.txt" "File2.txt"
Compare every text file in the current directory against one another.
FC "*.txt" "*.txt"
Compare two text files while ignoring any casing differences and limiting the amount of different lines that the FC command will look through before aborting, to one.
FC /c /LB1 "File1.txt "File2.txt"
Perform a binary comparison between two files.
FC /B "File1.txt" "File2.txt"
Compares two files or sets of files and displays the differences between
them
FC [/A] [/C] [/L] [/LBn] [/N] [/OFF[LINE]] [/T] [/U] [/W] [/nnnn]
[drive1:][path1]filename1 [drive2:][path2]filename2
FC /B [drive1:][path1]filename1 [drive2:][path2]filename2
/A Displays only first and last lines for each set of differences.
/B Performs a binary comparison.
/C Disregards the case of letters.
/L Compares files as ASCII text.
/LBn Sets the maximum consecutive mismatches to the specified
number of lines.
/N Displays the line numbers on an ASCII comparison.
/OFF[LINE] Do not skip files with offline attribute set.
/T Does not expand tabs to spaces.
/U Compare files as UNICODE text files.
/W Compresses white space (tabs and spaces) for comparison.
/nnnn Specifies the number of consecutive lines that must match
after a mismatch.
[drive1:][path1]filename1
Specifies the first file or set of files to compare.
[drive2:][path2]filename2
Specifies the second file or set of files to compare.
You now know how to use the Fc command to compare files directly from the command prompt.
If you liked this short guide take a look at a few of our other posts related to the windows command line, or if you really liked it consider enrolling in our video course where you will learn the ins and outs of the Windows command Line.
This course has everything you need to start learning about the windows command line along with batch scripting.
File attributes grant or deny certain rights to every file and folder. The attrib command can be used to view or change file attributes on files or folders.
The cipher command is a built in security tool, that can be used to encrypt or decrypt files and folders as well as wipe or overwrite deleted data.
A redirector or pipe is a special symbol that is used to redirect the input or output of a command or combine two or more commands in various ways.
Learn the Windows command line And Become an Expert!