head 명령어 (AIX 5.3·6.1)

핵심 정리

  • 파일이나 표준 입력의 앞부분을 지정한 줄 수나 바이트 수만큼 표준 출력에 씁니다.
  • 플래그가 없으면 앞의 10줄을 보여 줍니다.
  • -n Number(줄 수), -c Number(바이트 수), -Count(줄 수, 옛 형식)를 씁니다. 이식성을 생각하면 -Count 대신 -n을 씁니다.
  • 파일이 여러 개면 파일마다 ==> 파일이름 <== 머리글을 붙입니다.
  • 입력 파일은 텍스트 파일이어야 합니다.
  • AIX 5.3과 6.1 문서의 내용이 같습니다.
항목 내용
버전 AIX 5.3, AIX 6.1 (두 버전 내용 같음)
원문 IBM Commands Reference — 5.3 Volume 2, 6.1 Volume 2
파일 /usr/bin/head
관련 명령어 tail

목적

파일의 앞 몇 줄을 표시합니다.

영어 원문

Displays the first few lines of a file.

구문

text
head [ -Count | -c Number | -n Number ] [ File ... ]

설명

head 명령은 지정한 파일 각각(또는 표준 입력)에서 지정한 줄 수나 바이트 수를 표준 출력에 씁니다. 플래그를 지정하지 않으면 기본으로 앞의 10줄을 표시합니다. File 매개변수는 입력 파일의 이름이며, 입력 파일은 텍스트 파일이어야 합니다. 파일을 둘 이상 지정하면 파일마다 처음이 다음과 같습니다.

text
==> filename <==

짧은 파일 여러 개를 파일마다 구분해 표시하려면 다음과 같이 입력합니다.

bash
head -9999 filename1 filename2 ...
영어 원문

The head command writes to standard output a specified number of lines or bytes of each of the specified files, or of the standard input. If no flag is specified with the head command, the first 10 lines are displayed by default. The File parameter specifies the names of the input files. An input file must be a text file. When more than one file is specified, the start of each file will look like the following:

==> filename <==

To display a set of short files, identifying each one, enter:

example% head -9999 filename1 filename2...

플래그

플래그 설명
-Count 지정한 파일마다 앞에서부터 표시할 줄 수를 정합니다. Count는 양의 10진 정수여야 합니다. -n Number와 같지만, 이식성을 생각한다면 쓰지 않습니다.
-c Number 표시할 바이트 수를 정합니다. Number는 양의 10진 정수여야 합니다.
-n Number 지정한 파일마다 앞에서부터 표시할 줄 수를 정합니다. Number는 양의 10진 정수여야 합니다. -Count와 같습니다.
영어 원문
  • -Count — Specifies the number of lines from the beginning of each specified file to be displayed. The Count variable must be a positive decimal integer. This flag is equivalent to the -n Number flag, but should not be used if portability is a consideration.
  • -c Number — Specifies the number of bytes to display. The Number variable must be a positive decimal integer.
  • -n Number — Specifies the number of lines from the beginning of each specified file to be displayed. The number variable must be a positive decimal integer. This flag is equivalent to the -Count flag.

종료 상태

값 뜻
0 잘 끝났습니다.
0보다 큼 오류가 났습니다.
영어 원문

This command returns the following exit values:

  • 0 — Successful completion.
  • >0 — An error occurred.

예제

Test 파일의 앞 다섯 줄을 표시합니다. 다음 둘 중 하나를 입력합니다.

bash
head -5 Test
head -n 5 Test

관련 명령어: tail

영어 원문

To display the first five lines of the Test file, enter: head -5 Test

OR

head -n 5 Test

Related information:

  • tail command
  • Files command
  • Input and output redirection

리눅스(GNU)와 다른 점

항목 AIX 5.3·6.1 GNU head
음수 값 양의 정수만 받음 -n -5(끝의 5줄을 뺀 나머지), -c -5도 받음
단위 접미사 없음 -c 1K, -n 2M처럼 단위를 붙일 수 있음

AIX 5.3·6.1 문서에는 -q(머리글 숨김), -v(머리글 항상 표시) 같은 GNU 플래그가 없습니다.