Linux and UNIX Man Pages

Linux & Unix Commands - Search Man Pages

cmp(1) [netbsd man page]

CMP(1)							    BSD General Commands Manual 						    CMP(1)

cmp -- compare two files SYNOPSIS
cmp [-l | -s] file1 file2 [skip1 [skip2]] DESCRIPTION
The cmp utility 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. Bytes and lines are numbered beginning with one. The following options are available: -l Print the byte number (decimal) and the differing byte values (octal) for each difference. -s Print nothing for differing files; return exit status only. The optional arguments skip1 and skip2 are the byte offsets from the beginning of file1 and file2, respectively, where the comparison will begin. The offset is decimal by default, but may be expressed as an hexadecimal or octal value by preceding it with a leading ``0x'' or ``0''. The cmp utility exits with one of the following values: 0 The files are identical. 1 The files are different; this includes the case where one file is identical to the first part of the other. In the latter case, if the -s option has not been specified, cmp writes to standard output that EOF was reached in the shorter file (before any differences were found). >1 An error occurred. SEE ALSO
diff(1), diff3(1) STANDARDS
The cmp utility is expected to be IEEE Std 1003.2 (``POSIX.2'') compatible. BSD
June 6, 1993 BSD

Check Out this Related Man Page

cmp(1)							      General Commands Manual							    cmp(1)

       cmp - compare two files

       cmp [-l | -s] file1 file2  [ skip1 ]  [ skip2 ]

       The  command  compares two files.  If either file1 or file2 is `-', standard input is used for the file.  With no options, makes no comment
       if the files are the same.  If they differ, it reports the byte and line number at which the difference occurred to  standard  output.	If
       one file is an initial subsequence of the other a message including the file name is written to standard error.

       The optional skip1 and skip2 parameters are initial byte offsets into file1 and file2 respectively and may be either octal, by specifying a
       leading 0, or decimal.  When using skip1 and skip2 the offset is treated as the start of the respective input file.  Only one option may be
       specified  at  a  time.	Only one of the input files may be standard input at a time.  Because the line number is not calculated when using
       either of the options the use of either flag will increase the speed of

       -l Long format:	prints the byte number (decimal) and the differing bytes (octal) for each difference.

       -s Suppresses normal output and sets the exit code only.

       Exit code 0 is returned for identical files, 1 for different files, and 2 for an inaccessible or missing argument.

See Also
       comm(1), diff(1)

Man Page

14 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Comparing EBCDIC files

Hi Guys, I wish to compare two ebcdic files. diff utility manual says it only compares two text files line by line.. I doubt this will be good for ebcdic files. cmp utility does binary comparision but I do not find any thing in manual referring if it does support ebcdic file format. let... (2 Replies)
Discussion started by: RishiPahuja
2 Replies

2. UNIX for Dummies Questions & Answers

output difference in two files

Hi, Please help me, I have two files. I need to output the difference of contents of each file in another file. For example, I need to know the content of the file1 that does not exist on file2 and vice versa. Please take note that the size of the files are large. How can I do it using unix... (4 Replies)
Discussion started by: ayhanne
4 Replies

3. Shell Programming and Scripting

Check if 2 files are identical byte-to-byte?

In my server migration requirement, I need to compare if one file on old server is exactly the same as the corresponding file on the new server. For diff and comm, the inputs need to be sorted. But I do not want to disturb the content of the file and need to find byte-to-byte match. Please... (4 Replies)
Discussion started by: krishmaths
4 Replies

4. UNIX for Dummies Questions & Answers

Difference between two huge files

Hi, As per my requirement, I need to take difference between two big files(around 6.5 GB) and get the difference to a output file without any line numbers or '<' or '>' in front of each new line. As DIFF command wont work for big files, i tried to use BDIFF instead. I am getting incorrect... (13 Replies)
Discussion started by: pyaranoid
13 Replies

5. Shell Programming and Scripting

CMP two files with slight difference and return code

I am comparing two files which are identical except for the timestamp which is incorporated within the otherwise same 372 bytes. I am using the command: cmp -s $Todays_file $Yesterdays_file -i 372 When I run the command without the -i 372 it shows the difference i.e. the timestamp.... (5 Replies)
Discussion started by: gugs
5 Replies

6. Shell Programming and Scripting

File Comparison command but ignoring while spaces

Hello All, I am writing a file comparison utility and using the cmp command to compare 2file. But I need command that will compare 2 files and if the files are identical expect for differences in white spaces, then it should ignore those spaces and consider the two files equal. Is there a way to... (7 Replies)
Discussion started by: Veenak15
7 Replies

7. Shell Programming and Scripting

Print the difference

Suppose u have two files One file aa bb aa cc aa uu second file aa cc cc bb uu aa so to print the difference between to files i shud get cc bb What can be done (3 Replies)
Discussion started by: cdfd123
3 Replies

8. Shell Programming and Scripting

File Comparison Columnar?

I'm looking to build up a process which would compare 2 files and show difference, the difference needs to be done in such a way that it also shows which column value is differing. So i think of this. Run a diff between the files , then someway find which columns have different values need to... (6 Replies)
Discussion started by: dinjo_jo
6 Replies

9. Shell Programming and Scripting

Help with case (Shell: sh)

Help with case Hello I need some help with case since most of the examples I found are related to a choice menus I have 2 files (actually a lot of files with the specified prefix) in my dir e.g file1 & file2 I need to display: case1:if file1 & file2 exist :file1_no=$(ll file1 |wc -l);... (2 Replies)
Discussion started by: drbiloukos
2 Replies

10. Shell Programming and Scripting

finding difference between two files

Hi, I have two files one with 12486 lines second one with 13116 As per the comparsion between two files the count have 630 difference I used diff command to find the difference between two files but it's not understandable could any one suggest any command to get 630 records in a new... (4 Replies)
Discussion started by: thelakbe
4 Replies

11. Shell Programming and Scripting

compare multiple files and get the difference

Hi all, i have 50 files .data should be same in these 50 files , so my task is to find the difference. i need a logic , which finds difference between all files and print in output file with file name where it found that difference . i tried below logic , but its not giving me what i want. let... (2 Replies)
Discussion started by: deepakiniimt
2 Replies

12. Shell Programming and Scripting

Comparing text in 2 files and output difference in another file.

I have 2 files of almost same text apart from 2,3 ending lines. Now I want to get that difference in another file. e.g file1.txt is Filesystem Size Used Avail Use% Mounted on /dev/mapper/vg_livecd-lv_root 18G 2.4G 15G 14% / tmpfs 504M ... (12 Replies)
Discussion started by:
12 Replies

13. Shell Programming and Scripting

Syntax Error while using CMP function

Hi All, I am getting a syntax error message while trying to compare 2 files using the compare function (LINUX) command substitution: line 79: syntax error near unexpected token `(' command substitution: line 79: `cmp -s <(tr , \n < $COMMON_TMP/nt_per_gs.done | sort) <(tr , \n <... (5 Replies)
Discussion started by: dsfreddie
5 Replies

14. Shell Programming and Scripting

Script to compare 2 files and prints difference as output sidebyside

Hi All, Am trying script to compare 2 files and print the difference found from old file to new file on line by line basis on side by side display. Basically line by line comparision and files may contain blank line as well I know we have compare/diff commands but i don't how to make... (10 Replies)
Discussion started by: Optimus81
10 Replies