cat 명령어 (AIX 5.3·6.1)

핵심 정리

  • 파일을 차례로 읽어 표준 출력에 씁니다. 여러 파일을 이어 붙이거나 내용을 볼 때 씁니다.
  • 파일을 지정하지 않거나 -를 지정하면 표준 입력을 읽습니다.
  • 입력 파일 중 하나로 > 재지정을 하면 안 됩니다. 셸이 cat보다 먼저 파일을 비워 원래 내용을 잃습니다.
  • -n(줄 번호), -b(빈 줄 번호 생략), -v(보이지 않는 문자 표시, -e·-t와 함께), -q·-s(없는 파일 메시지 숨김), -r·-S(연속 빈 줄 하나로), -u(버퍼 없음).
  • AIX의 -s는 GNU와 달리 "없는 파일 메시지 숨김"이고, 빈 줄 줄이기는 -S·-r입니다.
  • 6.1에서 -Z(암호화된 파일을 암호화된 형식 그대로 덤프)가 생겼습니다.
항목 내용
버전 AIX 5.3, AIX 6.1 (6.1에서 -Z 플래그가 더해짐)
원문 IBM Commands Reference — 5.3 Volume 1, 6.1 Volume 1
파일 /usr/bin/cat
관련 명령어 pg, more, pr, ksh

목적

파일을 이어 붙이거나 표시합니다.

영어 원문

Concatenates or displays files.

구문

text
cat [ -q ] [ -r ] [ -s ] [ -S ] [ -u ] [ -Z ] [ -n [ -b ] ] [ -v [ -e ] [ -t ] ] [ - | File ... ]

-Z는 6.1 구문에만 있습니다.

설명

cat 명령은 File 매개변수를 차례로 읽어 표준 출력에 씁니다. 파일 이름을 지정하지 않으면 표준 입력을 읽습니다. 표준 입력을 뜻하는 파일 이름으로 -(대시)를 지정할 수도 있습니다.

주의: 재지정 기호 >(보다 큼 기호)로 출력을 입력 파일 중 하나로 보내지 마세요. 그러면 cat 명령이 읽기 전에 셸이 그 파일을 비우므로 입력 파일의 원래 데이터를 잃습니다. 자세한 내용은 Operating system and device management의 "Input and output redirection in the Korn shell or POSIX shell"을 봅니다.

영어 원문

The cat command reads each File parameter in sequence and writes it to standard output. If you do not specify a file name, the cat command reads from standard input. You can also specify a file name of - (dash) for standard input.

Attention: Do not redirect output to one of the input files using the redirection symbol, > (greater than symbol). If you do this, you lose the original data in the input file because the shell truncates the file before the cat command can read it. See "Input and output redirection in the Korn shell or POSIX shell" in Operating system and device management for more information.

플래그

플래그 설명
-b -n과 함께 쓰면 빈 줄에는 줄 번호를 붙이지 않습니다.
-e -v와 함께 쓰면 줄마다 끝에 $(달러 기호)를 표시합니다.
-n 출력 줄 앞에 1부터 차례로 줄 번호를 붙입니다.
-q 입력 파일을 찾지 못해도 메시지를 표시하지 않습니다. -s와 같습니다.
-r 연속된 빈 줄 여러 개를 빈 줄 하나로 바꿉니다. -S와 같습니다.
-s 입력 파일을 찾지 못해도 메시지를 표시하지 않습니다. -q와 같습니다. 참고: 예전에는 지금 -S가 하는 일을 -s가 했습니다.
-S 연속된 빈 줄 여러 개를 빈 줄 하나로 바꿉니다. -r과 같습니다.
-t -v와 함께 쓰면 탭 문자를 ^I로 표시합니다.
-u 출력을 버퍼에 모으지 않습니다. 기본은 버퍼를 씁니다.
-v 탭, 줄바꿈, 폼 피드를 빼고 인쇄할 수 없는 문자를 보이는 문자로 표시합니다(아래 설명).
- cat 명령이 표준 입력을 읽게 합니다.
-Z 암호화된 파일의 내용을 암호화된 형식 그대로 덤프합니다. 파일의 접근 키가 없어도 cat -Z를 할 수 있습니다. 6.1부터

-v의 표시 방식

  • ASCII 제어 문자(8진수 000037)는 ^n으로 표시합니다. n은 8진수 100137 범위의 대응하는 ASCII 문자(@, A, B, C, …, X, Y, Z, [, \, ], ^, _)입니다.
  • DEL 문자(8진수 0177)는 ^?로 표시합니다.
  • 그 밖의 인쇄할 수 없는 문자는 M-x로 표시합니다. x는 하위 7비트가 나타내는 ASCII 문자입니다.

-v와 함께 다음 옵션을 쓸 수 있습니다.

  • -e: 줄바꿈 앞, 줄 끝마다 $ 문자를 표시합니다.
  • -t: 탭을 ^I로, 폼 피드를 ^L로 표시합니다.

-v를 지정하지 않으면 -e와 -t는 무시합니다.

영어 원문
  • -b — Omits line numbers from blank lines, when specified with the -n flag.
  • -e — Displays a $ (dollar sign) at the end of each line, when specified with the -v flag.
  • -n — Displays output lines preceded by line numbers, numbered sequentially from 1.
  • -q — Does not display a message if the cat command cannot find an input file. This flag is identical to the -s flag.
  • -r — Replaces multiple consecutive empty lines with one empty line. This flag is identical to the -S flag.
  • -s — Does not display a message if the cat command cannot find an input file. This flag is identical to the -q flag. Note: Previously, the -s flag handled tasks now assigned to the -S flag.
  • -S — Replaces multiple consecutive empty lines with one empty line. This flag is identical to the -r flag.
  • -t — Displays tab characters as ^I if specified with the -v flag.
  • -u — Does not buffer output. The default is buffered output.
  • -v — Displays nonprinting characters as visible characters, with the exception of tabs, new-lines, and form-feeds. ASCII control characters (octal 000–037) are printed as ^n, where n is the corresponding ASCII character in the octal range 100–137 (@, A, B, C,..., X, Y, Z, [, \, ], ^, and _); the DEL character (octal 0177) is printed as ^?. Other non-printable characters are printed as M-x, where x is the ASCII character specified by the low-order seven bits. When used with the -v option, the following options may be used: -e A $ character will be printed at the end of each line prior to a new line. -t Tabs will be printed as ^I and form feeds will be printed as ^L The -e and -t options are ignored if the -v option is not specified.
  • - — Allows standard input to the cat command.
  • Z — Dumps the contents of encrypted files in encrypted format. Access keys to the encrypted file are not required to do cat -Z on the file.

종료 상태

값 뜻
0 모든 입력 파일을 잘 출력했습니다.
0보다 큼 오류가 났습니다.
영어 원문

This command returns the following exit values:

  • 0 — All input files were output successfully.
  • >0 — An error occurred.

예제

주의: 재지정 기호 >로 출력을 입력 파일 중 하나로 보내지 마세요.

  1. 파일을 화면에 표시합니다. notes 파일의 내용이 나옵니다. 파일이 화면에 보이는 줄 수보다 길면 일부가 화면 위로 지나갑니다. 한 쪽씩 보려면 pg 명령을 씁니다.
bash
cat notes
  1. 여러 파일을 이어 붙입니다. section1.1 뒤에 section1.2와 section1.3을 이은 section1 파일을 만듭니다.
bash
cat section1.1 section1.2 section1.3 >section1
  1. 없는 파일에 대한 오류 메시지를 숨깁니다. section2.1이 없으면 section2.2와 section2.3만 이어 붙입니다. -q를 쓰지 않아도 결과는 같지만 cat: cannot open section2.1 오류 메시지가 나옵니다. 셸 프로시저에서 cat을 쓸 때 이 메시지를 숨기면 좋습니다.
bash
cat -q section2.1 section2.2 section2.3 >section2
  1. 파일 하나를 다른 파일 끝에 덧붙입니다. >>는 section1.4의 사본을 section1 끝에 덧붙입니다. 파일을 바꾸려면 >를 씁니다.
bash
cat section1.4 >> section1
  1. 파일 끝에 글을 더합니다. notes 파일 끝에 Get milk on the way home이 더해집니다. cat은 입력 안내 없이 글을 기다리며, 다 썼으면 Ctrl-D를 누릅니다.
text
cat >>notes
Get milk on the way home
Ctrl-D
  1. 여러 파일과 키보드로 입력한 글을 이어 붙입니다. section3.1, 키보드 입력(빼기 기호가 가리킴), section3.3을 차례로 이어 section3 파일로 보냅니다.
bash
cat section3.1 - section3.3 >section3
영어 원문

Attention: Do not redirect output to one of the input files using the redirection symbol, > (caret).

  1. To display a file at the workstation, enter: cat notes

This command displays the data in the notes file. If the file is more than one less than the number of available display lines, some of the file scrolls off the screen. To list a file one page at a time, use the pg command.

  1. To concatenate several files, enter: cat section1.1 section1.2 section1.3 >section1

This command creates a file named section1 that is a copy of section1.1 followed by section1.2 and section1.3.

  1. To suppress error messages about files that do not exist, enter:

cat -q section2.1 section2.2 section2.3 >section2

If section2.1 does not exist, this command concatenates section2.2 and section2.3. The result is the same if you do not use the -q flag, except that the cat command displays the error message: cat: cannot open section2.1

You may want to suppress this message with the -q flag when you use the cat command in shell procedures.

  1. To append one file to the end of another, enter: cat section1.4 >> section1

The >> (two carets) appends a copy of section1.4 to the end of section1. If you want to replace the file, use the > (caret).

  1. To add text to the end of a file, enter:
cat >>notes
Get milk on the way home
Ctrl-D

This command adds Get milk on the way home to the end of the file called notes. The cat command does not prompt; it waits for you to enter text. Press the Ctrl-D key sequence to indicate you are finished.

  1. To concatenate several files with text entered from the keyboard, enter:
cat section3.1 - section3.3 >section3

This command concatenates the file section3.1 with text from the keyboard (indicated by the minus sign), and the file section3.3, then directs the output into the file called section3.

파일

파일 설명
/usr/bin/cat cat 명령이 들어 있습니다.

관련 명령어: ksh, pg

영어 원문
  • /usr/bin/cat — Contains the cat command.

Related information:

  • ksh command
  • Files command
  • Input and output redirection in the Korn shell or POSIX shell
  • Shells command

리눅스(GNU)와 다른 점

항목 AIX 5.3·6.1 GNU cat
-s 없는 파일 메시지 숨김(-q와 같음) 연속 빈 줄을 하나로
-S·-r 연속 빈 줄을 하나로 없음
-q 없는 파일 메시지 숨김 없음
-e·-t -v와 함께 써야 효과가 있음 혼자 써도 -vE·-vT와 같음
-Z 암호화 파일 덤프(6.1) 없음

AIX 5.3·6.1 문서에는 -A(모든 문자 표시), -E, -T 같은 GNU 플래그가 없습니다.