compress 명령어 (AIX 5.3·6.1)
https://archive.horanglab.com/posts/aix-cmd-compress
핵심 정리
- 적응형 Lempel-Ziv(LZW) 부호로 파일을 압축해 원본을
파일.Z로 바꿉니다. 권한이 있으면 소유권, 모드, 수정 시각을 유지합니다. compress -v 파일(압축률 출력),compress -c 파일 > 파일.Z(원본을 두고 표준 출력으로),compress -f(이미 있는.Z를 덮어쓰고, 줄지 않아도 압축).- 압축해도 크기가 줄지 않으면 원본을 그대로 두고 종료 상태 2를 돌려줍니다.
- 풀기는
uncompress 파일.Z나compress -d, 내용만 보기는zcat 파일.Z입니다. - 보통 텍스트는 50~60% 줄어듭니다. 요즘은 압축률이 더 좋은
gzip을 많이 씁니다.
| 항목 | 내용 |
|---|---|
| 버전 | AIX 5.3, AIX 6.1 (내용이 같고, 6.1 문서에 RBAC 안내가 더해짐) |
| 원문 | IBM Commands Reference — 5.3 Volume 1, 6.1 Volume 1 |
| 파일 | /usr/bin/compress |
| 관련 명령어 | uncompress, zcat, pack, unpack, gzip |
목적
데이터를 압축합니다.
영어 원문
Compresses data.
구문
compress [ -c ] [ -C ] [ -d ] [ -F ] [ -f ] [ -n ] [ -q ] [ -v ] [ -V ] [ -b Bits ] [ File ... ]
설명
compress 명령은 적응형 Lempel-Ziv 부호로 파일 크기를 줄입니다. File 매개변수로 준 원본 파일은 되도록 이름 끝에 .Z를 붙인 압축 파일로 바뀝니다. 실행한 프로세스에 적절한 권한이 있으면 압축 파일은 원본의 소유권, 모드, 수정 시각을 유지합니다. 파일 경로가 1023바이트를 넘으면 동작하지 않습니다. 파일을 주지 않으면 표준 입력을 압축해 표준 출력에 씁니다. 압축해도 크기가 줄지 않으면 표준 오류에 메시지를 쓰고 원본을 바꾸지 않습니다.
참고: 파일을 바꾸려면 권한이 맞아야 합니다.
압축 정도는 입력 크기, Bits로 정한 코드당 비트 수, 공통 부분 문자열의 분포에 따라 다릅니다. 보통 소스 코드나 영문 텍스트는 50~60% 줄어듭니다. compress의 압축은 보통 pack이 쓰는 Huffman 부호나 적응형 Huffman 부호보다 더 작고 빠릅니다.
영어 원문
The compress command compresses data, using adaptive Lempel-Zev coding to reduce the size of files. Each original file specified by the File parameter is replaced when possible by a compressed file with a .Z appended to its name. If the invoking process has appropriate privileges, the compressed file retains the same ownership, modes, and modification time of the original file. If the path of the file specified is more than 1023 bytes the command does not work. If no files are specified, the standard input is compressed to the standard output. If compression does not reduce the size of a file, a message is written to standard error and the original file is not replaced.
Note: Files must have correct permissions to be replaced.
The amount of compression depends on the size of the input, the number of bits per code specified by the Bits variable, and the distribution of common substrings. Typically, source code or English text is reduced by 50 to 60%. The compression of the compress command is usually more compact and takes less time to compute than the compression achieved by Huffman coding (as used in the pack command) or adaptive Huffman coding.
플래그
| 플래그 | 설명 |
|---|---|
-b Bits |
공통 부분 문자열을 바꾸는 데 쓸 최대 비트 수(916, 기본 16). 먼저 9비트 코드(257512)를 모두 쓰고, 다음 10비트 코드를 쓰는 식으로 이 한도까지 갑니다. |
-c |
표준 출력에 씁니다. 파일은 바꾸지 않습니다. |
-C |
BSD 2.0과 호환되는 출력을 만듭니다. |
-d |
uncompress와 똑같이 동작합니다. |
-f, -F |
강제로 압축합니다(둘은 같음). 파일.Z가 이미 있으면 덮어씁니다. Bits 한도에 닿은 뒤에는 압축률을 주기적으로 검사해, 올라가면 기존 코드 사전을 계속 쓰고 내려가면 부분 문자열 표를 버리고 다시 만들어 파일의 다음 블록에 맞춥니다. .Z가 이미 있는데 -f가 없고 백그라운드가 아니면 덮어쓸지 묻습니다. |
-n |
압축 파일에서 헤더를 뺍니다. 이렇게 만든 파일은 uncompress -n으로 풀어야 합니다. |
-q |
-v의 압축 통계를 보여 주지 않습니다. -v와 -q가 여럿이면 마지막 것을 따릅니다. |
-v |
압축률을 씁니다. |
-V |
현재 버전과 컴파일 옵션을 표준 오류에 씁니다. |
영어 원문
-bBits — Specifies the maximum number of bits to use to replace common substrings in the file. The value of the Bits variable must be in the range from 9 bits through 16 bits, with the default being 16 bits. When compressing data, the algorithm first uses all of the 9-bit codes (257 through 512) to replace as many substrings as possible. Then it uses all 10-bit codes, and so on, continuing until the limit specified by the-bflag is reached.-c— Writes to standard output. No files are changed.-C— Produces output compatible with the Berkeley Software Distribution (BSD) Revision 2.0.-d— Causes the compress command to function exactly like the uncompress command.-for-F— Forces compression. The-fand-Fflags are interchangeable. Overwrites the File.Z file if it already exists. After the value of the Bits variable is attained, the compress command periodically checks the compression ratio. If it is increasing, the compress command continues to use the existing code dictionary. However, if the compression ratio decreases, the compress command discards the table of substrings and rebuilds it. Rebuilding the table allows the algorithm to adapt to the next block of the file. When the .Z file already exist, if the-fflag is not given, and the process is not running in the background, it prompts to verify whether to overwrite the existing .Z file.-n— Omits the compressed file header from the compressed file. Note: If this option is used, the-nflag should also be used when using the uncompress command to uncompress the file.-q— Suppresses the display of compression statistics generated by the-vflag. If several-vand-qflags are on the same command line, the last one specified controls the display of the statistics.-v— Writes the percentage of compression.-V— Writes the current version and compile options to standard error.
매개변수
| 매개변수 | 설명 |
|---|---|
| File | 압축할 파일. |
영어 원문
- File — Specifies the file to compress.
Return Values
오류가 나면 종료 상태는 1, 파일을 압축하지 않고 끝나면 2, 그 밖에는 0입니다. 다음 경우 오류로 보고 1로 끝납니다.
- 입력 파일이 보통 파일이 아닙니다.
- 입력 파일 이름이 너무 길어
.Z를 붙일 수 없습니다. - 입력 파일을 읽을 수 없거나 출력 파일을 쓸 수 없습니다.
영어 원문
If an error occurs, the exit status is 1. If the compress command exits without compressing a file, it exits with a status of 2. Otherwise, the compress command exits with a status of 0.
The compress command detects an error and exits with a status of 1 if any of the following events occur:
An input file is not a regular file.
An input file name is too long to append the .Z extension.
An input file cannot be read or an output file cannot be written.
종료 상태
| 값 | 뜻 |
|---|---|
| 0 | 성공 |
| 1 | 오류 |
| 2 | 압축하면 오히려 커져서(-f 없이) 압축하지 않은 파일이 있음 |
| 2보다 큼 | 오류 |
영어 원문
- 0 — Successful completion.
- 1 — An error occurred.
- 2 — One or more files were not compressed because they would have increased in size (and the
-fflag was not specified). >2— An error occurred.
보안
RBAC 사용자와 Trusted AIX 사용자는 주의하세요. 이 명령은 특권 작업을 할 수 있으며, 특권 작업은 특권 사용자만 할 수 있습니다. 특권과 권한 목록은 lssecattr 명령이나 getcmdattr 하위 명령으로 봅니다(6.1 문서에만 있음).
영어 원문
Attention RBAC users and Trusted AIX users: This command can perform privileged operations. Only privileged users can run privileged operations. For more information about authorizations and privileges, see Privileged Command Database in Security. For a list of privileges and the authorizations associated with this command, see the lssecattr command or the getcmdattr subcommand.
예제
foo 파일을 압축하고 압축률을 표준 오류에 씁니다. foo는 압축되어 foo.Z로 바뀝니다.
compress -v foo
자주 쓰는 형태:
compress -v /var/log/old/*.log # 여러 파일 압축
tar -cvf - ./app | compress > app.tar.Z # tar와 함께
zcat app.tar.Z | tar -tvf - # 풀지 않고 목록
영어 원문
To compress the foo file and write the percentage of compression to standard error, enter: compress -v foo
The foo file is compressed and renamed foo.Z.
Related information:
- pack command
- uncompress command
- unpack command
- zcat command
- Commands command
리눅스(GNU)와 다른 점
리눅스에서도 compress·uncompress(ncompress 패키지)를 쓸 수 있지만 거의 쓰이지 않고 gzip·gunzip·zcat(또는 bzip2, xz, zstd)을 씁니다. GNU gzip -d와 zcat은 .Z 파일도 풀 수 있어 AIX에서 만든 .Z를 리눅스에서 열 때 편합니다. AIX에도 AIX Toolbox의 gzip이 흔히 설치되어 있습니다.