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.
[ejr@hobbes manipulate]$ cmp dearliza → dearhenry dearliza dearhenry differ: char 20, line 2 [ejr@hobbes manipulate]$ |
[ejr@hobbes manipulate]$ cmp limerick → limericks cmp: EOF on limerick [ejr@hobbes manipulate]$ |
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.
3.17.5.68