Comparing files
A comparison between two similar files makes sense in order to know what differences exist between the two files. For example, comparing the results obtained by a command ran on two sets of data. Another example can be comparing an older and a newer version of a shell script file in order to know what modifications have been made in script. Shell provides the diff
command for file comparison.
Files comparison using diff
The diff
command is used to compare files line by line. The syntax of using the diff
command is as follows:
diff [option] file1 file2
Where, file1
and file2
are the files to be compared.
The options of the
diff
command are explained in the following table:
Option |
Description |
---|---|
|
Only print if files differ |
|
Print a message on |
|
Display the |
|
Do case-insensitive comparison of the files' content |
|
Ignore changes in the number of whitespace |
|
Output |