fortypoundhead.com

CMP

Posted On 2007-04-27 by FortyPoundHead
Keywords: Command Reference
Tags: Linux Commandline Linux
Views: 1496


Compare two files, and if they differ, tells the first byte and line number where they differ.

You can use the `cmp'' command to show the offsets and line numbers where two files differ. `cmp'' can also show all the characters that differ between the two files, side by side.


SYNTAX
cmp options... FromFile [ToFile]

OPTIONS
Multiple single letter options (unless they take an argument)
can be combined into a single command line word:
so `-cl'' is equivalent to `-c -l''.

`-c''
Print the differing characters. Display control characters as a
`^'' followed by a letter of the alphabet and precede characters
that have the high bit set with `M-'' (which stands for "meta").

`--ignore-initial=BYTES''
Ignore any differences in the the first BYTES bytes of the input
files. Treat files with fewer than BYTES bytes as if they are
empty.

`-l''
Print the (decimal) offsets and (octal) values of all differing
bytes.

`--print-chars''
Print the differing characters. Display control characters as a
`^'' followed by a letter of the alphabet and precede characters
that have the high bit set with `M-'' (which stands for "meta").

`--quiet''
`-s''
`--silent''
Do not print anything; only return an exit status indicating
whether the files differ.

`--verbose''
Print the (decimal) offsets and (octal) values of all differing
bytes.

`-v''
`--version''
Output the version number of `cmp''.

The file name `-'' is always the standard input. `cmp'' also uses the
standard input if one file name is omitted.

An exit status of 0 means no differences were found, 1 means some
differences were found, and 2 means trouble.
Example

$ cmp tnsnames.ora tnsnames.old

Notes
`cmp'' reports the differences between two files character by character, instead of line by line. As a result, it is more useful than `diff'' for comparing binary files. For text files, `cmp'' is useful mainly when you want to know only whether two files are identical.

For files that are identical, `cmp'' produces no output. When the files differ, by default, `cmp'' outputs the byte offset and line number where the first difference occurs. You can use the `-s'' option to suppress that information, so that `cmp'' produces no output and reports whether the files differ using only its exit status.
Unlike `diff'', `cmp'' cannot compare directories; it can only compare two files.


About the Author

FortyPoundHead has posted a total of 1974 articles.

 


Comments On This Post

No comments on this post yet!


Do you have a thought relating to this post? You can post your comment here. If you have an unrelated question, you can use the Q&A section to ask it.

Or you can drop a note to the administrators if you're not sure where you should post.


Your IP address is:54.162.181.75

Before you can post, you need to prove you are human. If you log in, this test goes away.




Recent Forum Posts

Advanced search added
dwirch posted on September 23, 2017 at about 13:44 in Site News

Job Spammer: Gaurav Mehta - AgreeYa Solutions
dwirch posted on September 22, 2017 at about 10:35 in Spammers

Job Spammer: Prutha Siri - Javelin Systems
dwirch posted on September 10, 2017 at about 6:15 in Spammers

New security implemented
dwirch posted on September 7, 2017 at about 7:16 in Site News

Malicious IP Checker Companion Tool
dwirch posted on August 12, 2017 at about 20:24 in Site News

Job Spammer: Steve Adams
dwirch posted on August 8, 2017 at about 7:44 in Spammers