Little Girl's Mostly Linux Blog

CompareFiles

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
pineapples

apples
oranges
bananas

cmp

  • Compare file1 with file2:
  • cmp file1 file2
    • The output will be:
    • file1 file2 differ: byte 8, line 2
  • Compare file1 with file3:
  • cmp file1 file3
    • You will get no output because the files are identical.

diff

  • Compare file1 with file2:
  • diff -y file1 file2
    • The output will be:
    • apples                                                          apples
      oranges                                                       |
      bananas                                                         bananas
                                                                    > pineapples
      
  • Compare file1 with file3:
  • diff -y file1 file3
    • The output will be:
    • apples                                                          apples
      oranges                                                         oranges
      bananas                                                         bananas
      


Obligatory Happy Ending

And they all lived happily ever after. The end.

Leave a Comment »

No comments yet.

RSS feed for comments on this post. TrackBack URI

Comment:

Create a free website or blog at WordPress.com.