cmp 명령어 (AIX 5.3·6.1)
https://archive.horanglab.com/posts/aix-cmd-cmp
핵심 정리
- 두 파일을 바이트 단위로 비교합니다. 같으면 아무것도 표시하지 않고, 다르면 처음 다른 곳의 바이트 번호와 줄 번호를 표시합니다.
- 텍스트가 아닌 파일은
cmp로, 텍스트 파일은diff로 비교하는 것이 보통입니다. -l은 다른 곳마다 바이트 번호(10진)와 다른 바이트 값(8진)을 모두 보여 줍니다.-s는 아무것도 출력하지 않고 종료 값만 돌려줍니다. 셸 스크립트의if에 씁니다.- 종료 값은 0(같음), 1(다름, 한쪽이 다른 쪽의 앞부분인 경우 포함), 2 이상(오류)입니다.
- AIX 5.3과 6.1 문서의 내용이 같습니다.
| 항목 | 내용 |
|---|---|
| 버전 | AIX 5.3, AIX 6.1 (두 버전 내용 같음) |
| 원문 | IBM Commands Reference — 5.3 Volume 1, 6.1 Volume 1 |
| 파일 | /usr/bin/cmp |
| 관련 명령어 | diff, comm |
목적
두 파일을 비교합니다.
영어 원문
Compares the contents of two files and reports the first character that differs.
구문
cmp [ -l | -s ] File1 File2
설명
cmp 명령은 File1과 File2 매개변수로 지정한 파일을 비교해 결과를 표준 출력에 씁니다. File1이나 File2에 -(빼기)를 지정하면 그 파일 대신 표준 입력을 읽습니다. 표준 입력으로 읽을 수 있는 파일은 하나뿐입니다.
기본으로 파일이 같으면 아무것도 표시하지 않습니다. 다르면 처음 다른 곳의 바이트 번호와 줄 번호를 표시합니다. -l 플래그를 지정했고 한 파일이 다른 파일의 앞부분과 같으면(곧, 차이를 찾기 전에 한 파일의 끝에 이르면) 그 사실을 알립니다.
보통 텍스트가 아닌 파일은 cmp로, 텍스트 파일은 diff 명령으로 비교합니다.
영어 원문
The cmp command compares files designated by the File1 and File2 parameters and writes the results to standard output. If you specify a - (minus sign) for either the File1 or File2 parameter, the cmp command reads standard input for that file. Only one file can be read from standard input. Under default conditions, the cmp command displays nothing if the files are the same. If they differ, the cmp command displays the byte and line number at which the first difference occurs. If the -l flag is specified and if one file is an initial subsequence of the other (that is, if the cmp command reads an end-of-file character in one file before finding any differences), the cmp command notes this. Normally, use the cmp command to compare non-text files and the diff command to compare text files.
플래그
| 플래그 | 설명 |
|---|---|
-l |
(소문자 L) 다른 곳마다 바이트 번호를 10진수로, 다른 바이트들을 8진수로 표시합니다. |
-s |
종료 값만 돌려줍니다. 0은 같은 파일, 1은 다른 파일, 2는 접근할 수 없는 파일이나 빠진 옵션입니다. |
영어 원문
-l— (Lowercase L) Displays, for each difference, the byte number in decimal and the differing bytes in octal.-s— Returns only an exit value. A value of 0 indicates identical files; value of 1 indicates different files; a value of 2 indicates inaccessible file or a missing option.
종료 상태
| 값 | 뜻 |
|---|---|
| 0 | 파일이 같습니다. |
| 1 | 파일이 다릅니다. 한 파일이 다른 파일의 앞부분과 같은 경우에도 이 값을 돌려줍니다. |
| 1보다 큼 | 오류가 났습니다. |
영어 원문
This command returns the following exit values:
- 0 — The files are identical.
- 1 — The files are different. This value is given even if one file is an initial subsequence of the other (one file is identical to the first part of the other).
>1— An error occurred.
예제
- 두 파일이 같은지 알아봅니다.
prog.o.bak와prog.o를 비교해, 같으면 메시지가 없고 다르면 처음 다른 곳을 보여 줍니다.
cmp prog.o.bak prog.o
prog.o.bak prog.o differ: char 4, line 1
cmp: EOF on prog.o.bak 메시지가 나오면 prog.o의 앞부분은 prog.o.bak와 같고, prog.o에 데이터가 더 있다는 뜻입니다.
- 서로 다른 바이트를 모두 표시합니다. 다른 곳마다 바이트 번호(10진)와 다른 바이트(8진)를 보여 줍니다. 예를 들어 다섯째 바이트가
prog.o.bak에서는 8진수 101,prog.o에서는 141이면 다음과 같이 표시합니다.
cmp -l prog.o.bak prog.o
5 101 141
- 메시지 없이 두 파일을 비교합니다. 같으면
0, 다르면1, 오류면2를 종료 값으로 돌려줍니다. 셸 프로시저에서 흔히 씁니다. 다음 셸 프로시저 일부는 두 파일이 같으면No change를 표시합니다.
cmp -s prog.c.bak prog.c
if cmp -s prog.c.bak prog.c
then
echo No change
fi
영어 원문
- To determine whether two files are identical, enter:
cmp prog.o.bak prog.o
This compares prog.o.bak and prog.o. If the files are identical, then a message is not displayed. If the files differ, then the location of the first difference is displayed; for example: prog.o.bak prog.o differ: char 4, line 1
If the message cmp: EOF on prog.o.bak is displayed, then the first part of prog.o is identical to prog.o.bak, but there is additional data in prog.o.
- To display each pair of bytes that differ, enter:
cmp -l prog.o.bak prog.o
This compares the files, and then displays the byte number (in decimal) and the differing bytes (in octal) for each difference. For example, if the fifth byte is octal 101 in prog.o.bak and 141 in prog.o, the cmp command displays: 5 101 141
- To compare two files without writing any messages, enter:
cmp -s prog.c.bak prog.c
This gives an exit value of 0 if the files are identical, a value of 1 if different, or a value of 2 if an error occurs. This form of the command is normally used in shell procedures. For example:
if cmp -s prog.c.bak prog.c then
echo No change
fi
This partial shell procedure displays No change if the two files are identical.
파일
| 파일 | 설명 |
|---|---|
/usr/bin/cmp |
cmp 명령이 들어 있습니다. |
관련 명령어: comm, diff, ksh
영어 원문
- /usr/bin/cmp — Contains the cmp command.
Related reference:
- comm Command
Related information:
- diff command
- ksh command
- Files command
- Input and output redirection overview
리눅스(GNU)와 다른 점
| 항목 | AIX 5.3·6.1 | GNU cmp |
|---|---|---|
-l 출력 |
바이트 번호와 8진 값 | 같음 |
AIX 5.3·6.1 문서에는 -b(다른 바이트를 문자로 표시), -i(앞부분 건너뛰기), -n(비교할 바이트 수) 같은 GNU 플래그가 없습니다.