Compare files
This page was last updated on October 15, 2009.
There are various command line ways to compare files. Presented here are cmp and diff. To see how these work, create these three text files, making file1 and file3 identical:
file1 | file2 | file3 |
apples oranges bananas |
apples
bananas |
apples oranges bananas |
cmp
- Compare file1 with file2:
- The output will be:
- Compare file1 with file3:
- You will get no output because the files are identical.
cmp file1 file2
file1 file2 differ: byte 8, line 2
cmp file1 file3
diff
- Compare file1 with file2:
- The output will be:
- Compare file1 with file3:
- The output will be:
diff -y file1 file2
apples apples oranges | bananas bananas > pineapples
diff -y file1 file3
apples apples oranges oranges bananas bananas
Obligatory Happy Ending
And they all lived happily ever after. The end.
Comment: