[Next] [Previous] [Up] [Top] [Contents]

8.1 Working With Files

8.1.1 cmp - compare file contents

The cmp command compares two files, and (without options) reports the location of the first difference between them. It can deal with both binary and ASCII file comparisons. It does a byte-by-byte comparison.

Syntax

cmp [options] file1 file2 [skip1] [skip2]

The skip numbers are the number of bytes to skip in each file before starting the comparison.

Common Options

-l report on each difference

-s report exit status only, not byte differences

Examples

Given the files mon.logins: and tues.logins:

ageorge ageorge

bsmith cbetts

cbetts jchen

jchen jdoe

jmarsch jmarsch

lkeres lkeres

mschmidt proy

sphillip sphillip

wyepp wyepp

The comparison of the two files yields:

% cmp mon.logins tues.logins

mon.logins tues.logins differ: char 9, line 2

The default it to report only the first difference found.

This command is useful in determining which version of a file should be kept when there is more than one version.


Introduction to Unix - 14 AUG 1996
[Next] [Previous] [Up] [Top] [Contents]