Comparing Files with cmp

Suppose you’ve been working on the dearliza file and you want to know how it differs from the dearhenry file. Using cmp, you can compare the two files as shown in Code Listing 6.13.

Code Listing 6.13. cmp gives just the facts about the first difference between two files.
[ejr@hobbes manipulate]$ cmp dearlizadearhenry
dearliza dearhenry differ: char 20, line 2
[ejr@hobbes manipulate]$

Code Listing 6.14. cmp also tells you if the files matched until one ended (EOF stands for “end of file”).
[ejr@hobbes manipulate]$ cmp limericklimericks
cmp: EOF on limerick
[ejr@hobbes manipulate]$

To compare files with cmp:

  • cmp dearliza dearhenry

    At the shell prompt, type cmp followed by both filenames. As Code Listing 6.13 shows, these two files are not the same. If the files are identical, you’ll find yourself back at the shell prompt with no comment from cmp. If both files are identical until one of them ends—that is, say, the first 100 lines are the same, but one continues and the other ends—then you’ll see an EOF (end of file) message, as in Code Listing 6.14.

✓ Tips

  • You can find out other ways that files differ using diff, as described in the next section, Finding Differences in Files with diff.

  • Unix provides an exit status message that you can use to get more information about how the program stopped and why. See Using Advanced Redirection in Chapter 17 for more information.

  • You can also use diff to find out which files are in one directory but not another. Just type diff followed by the names of the two directories; for example, diff /home/ejr/Directory/home/ejr/ Newdirectory

  • You might also check out the section, Finding Differences in Files with sdiff, for yet another way to compare files.


..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.17.5.68