cmp- Unix, Linux Command


Advertisements

Previous Page
Next Page  
 

NAME

cmp - Compare two files byte by byte

SYNOPSIS

cmp [OPTION]... FILE1 [FILE2 [SKIP1 [SKIP2]]]

DESCRIPTION

cmpIt compares two files of any type and writes the results to the standard output. By default, cmp is silent if the files are the same; if they differ, the byte and line number at which the first difference occurred is reported..

Options

Tag Description
-b, --print-bytes print differing bytes.
-i, --ignore-initial=SKIP skip first SKIP bytes of both files.
-i, --ignore-initial=SKIP1:SKIP2 skip first SKIP1 bytes of FILE1 and first SKIP2 bytes of FILE2
-l, --verbose output byte numbers and differing byte values
-n, --bytes=LIMIT compare at most LIMIT bytes.
-s, --quiet, --silent suppress all normal output.
--help display a help message and exit.
-v, --version output version information and exit.

EXAMPLES

EXAMPLE-1:

Compare two files file1.txt and file2.txt

file1 content: "My name is Ram"

file2 content: "My name is Shyam"

$ cmp file1.txt file2.txt

output: file1.txt file2.txt differ: byte 12, line 1

EXAMPLE-2:

Skip same number of initial bytes from both input files.

$ cmp -i 5 file1.txt file2.txt

output: file1.txt file2.txt differ: byte 7, line 1
So we can see that the initial 5 bytes were skipped.

EXAMPLE-3:

To Skip different number of initial bytes from both input files

$ cmp -i 5:2 file1.txt file2.txt 

output: file1.txt file2.txt differ: byte 1, line 1

EXAMPLE-4:

To display bytes that differ from file1.txt and file2.txt

$ cmp -l -i 5:2 file1.txt file2.txt

output>

1 155  40
 2 145 156
 3  40 141
 4 151 155
 5 163 145
 7 115 151
 8 157 163
 9 150  40
10 141 115
11 153 157
12  12 150
cmp: EOF on file1.txt

EXAMPLE-5:

To define Upper limit on number of bytes to compare between file1.txt and file2.txt

$ cmp -l -n 10 -i 5:2 file1.txt file2.txt 

output:
1 155 40 2 145 156 3 40 141 4 151 155 5 163 145 7 115 151 8 157 163 9 150 40 10 141 115

EXAMPLE-6:

To compare version

$ cmp -v

output:
cmp (GNU diffutils) 3.3
Copyright (C) 2013 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>.
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

Written by Torbjörn Granlund and David MacKenzie.

 



Previous Page
Next Page