tail 명령어 (AIX 5.3·6.1)

핵심 정리

  • 파일의 지정한 위치부터 끝까지를 표준 출력에 씁니다. 파일이 없으면 표준 입력을 읽습니다.
  • 플래그가 없으면 마지막 10줄을 보여 줍니다(-n 10과 같음).
  • 위치 단위는 -n(줄), -c(바이트), -m(다중 바이트 문자), -b(512바이트 블록), -k(1KB 블록)로 정합니다.
  • 값 앞에 +를 붙이면 처음부터, -를 붙이거나 아무것도 붙이지 않으면 끝에서부터 셉니다.
  • -f는 끝에 이르러도 끝내지 않고 늘어나는 내용을 계속 보여 줍니다. 로그를 지켜볼 때 씁니다.
  • -r은 파일을 끝에서부터 거꾸로 보여 줍니다. 파일이 20,480바이트보다 크면 마지막 20,480바이트만 보여 줍니다.
항목 내용
버전 AIX 5.3, AIX 6.1 (내용 거의 같음, 5.3에만 -r에 대한 한 문장이 더 있음)
원문 IBM Commands Reference — 5.3 Volume 5, 6.1 Volume 5
파일 /usr/bin/tail
관련 명령어 head, pg, dd

목적

파일의 마지막 몇 줄을 표시합니다.

영어 원문

Displays the last few lines of a file.

구문

기본 구문:

text
tail [ -f ] [ -c Number | -n Number | -m Number | -b Number | -k Number ] [ File ]

줄을 거꾸로 표시할 때:

text
tail [ -r ] [ -n Number ] [ File ]

설명

tail 명령은 File 매개변수로 지정한 파일을 지정한 지점부터 표준 출력에 씁니다. 파일을 지정하지 않으면 표준 입력을 씁니다.

Number 변수는 표준 출력에 쓸 단위의 수를 정하며, 양수나 음수를 쓸 수 있습니다.

  • 값 앞에 +(더하기)가 있으면 파일 처음에서 지정한 단위만큼 떨어진 곳부터 씁니다.
  • 값 앞에 -(빼기)가 있으면 파일 끝에서 지정한 단위만큼 떨어진 곳부터 씁니다.
  • 값 앞에 +도 -도 없으면 파일 끝에서 지정한 단위만큼 떨어진 곳부터 읽습니다.

시작 지점을 셀 단위는 -b, -c, -k, -m, -n 플래그로 정합니다. 이 플래그를 하나도 지정하지 않으면 파일의 마지막 10줄을 읽어 표준 출력에 씁니다. 명령줄에 -n 10을 입력한 것과 같습니다.

-m 플래그는 단일 바이트와 2바이트 문자 환경 모두에서 일관된 결과를 냅니다. 입력이 다중 바이트 문자가 든 텍스트 파일이면 -c 플래그는 조심해서 써야 합니다. 출력이 문자 경계에서 시작하지 않을 수 있기 때문입니다.

영어 원문

The tail command writes the file specified by the File parameter to standard output beginning at a specified point. If no file is specified, standard input is used. The Number variable specifies how many units to write to standard output. The value for the Number variable can be a positive or negative integer. If the value is preceded by + (plus sign), the file is written to standard output starting at the specified number of units from the beginning of the file. If the value is preceded by - (minus sign), the file is written to standard output starting at the specified number of units from the end of the file. If the value is not preceded by + (plus sign) or - (minus sign), the file is read starting at the specified number of units from the end of the file.

The type of unit used by the Number variable to determine the starting point for the count is determined by the -b, -c, -k, -m, or -n flag. If one of these flags is not specified, the tail command reads the last ten lines of the specified file and writes them to standard output. This is the same as entering -n 10 at the command line.

The -m flag provides consistent results in both single- and double-byte character environments. The -c flag should be used with caution when the input is a text file containing multibyte characters, because output can be produced that does not start on a character boundary.

플래그

플래그 설명
-b Number Number가 가리키는 512바이트 블록 위치부터 파일을 읽습니다.
-c Number Number가 가리키는 바이트 위치부터 파일을 읽습니다.
-f 입력 파일이 일반 파일이거나 File 매개변수가 FIFO(선입선출)면, 입력 파일의 마지막 지정 단위를 복사한 뒤에도 끝내지 않고, 입력 파일에 단위가 더해지는 대로 계속 읽어 복사합니다. File 매개변수가 없고 표준 입력이 파이프면 -f를 무시합니다. tail -f로 다른 프로세스가 쓰고 있는 파일이 늘어나는 것을 지켜볼 수 있습니다.
-k Number Number가 가리키는 1KB 블록 위치부터 파일을 읽습니다.
-m Number Number가 가리키는 다중 바이트 문자 위치부터 파일을 읽습니다. 단일 바이트와 2바이트 문자 코드 세트 환경 모두에서 일관된 결과를 냅니다.
-n Number Number의 부호(+, -, 또는 없음)에 따라 첫 줄이나 마지막 줄 위치에서 Number줄만큼 떨어진 곳부터 파일을 읽습니다.
-r 파일의 끝에서부터 거꾸로 출력합니다. 기본으로 파일 전체를 거꾸로 출력하며, 파일이 20,480바이트보다 크면 마지막 20,480바이트만 표시합니다. 5.3 문서에는 "-r은 -n과 함께 쓸 때만 유효하고, 아니면 무시한다"는 문장이 더 있습니다.
영어 원문
  • -b Number — Reads the specified file beginning at the 512-byte block location indicated by the Number variable.
  • -c Number — Reads the specified file beginning at the byte location indicated by the Number variable.
  • -f — If the input file is a regular file or if the File parameter specifies a FIFO (first-in-first-out), the tail command does not terminate after the last specified unit of the input file has been copied, but continues to read and copy additional units from the input file as they become available. If no File parameter is specified and standard input is a pipe, the -f flag is ignored. The tail -f command can be used to monitor the growth of a file being written by another process.
  • -k Number — Reads the specified file beginning at the 1KB block location indicated by the Number variable.
  • -m Number — Reads the specified file beginning at the multibyte character location indicated by the Number variable. Using this flag provides consistent results in both single- and double-byte character-code-set environments.
  • -n Number — Reads the specified file from the first or last line location as indicated by the sign (+ or - or none) of the Number variable and offset by the number of lines Number.
  • -r — Displays the output from the end of the file in reverse order. The default for the -r flag prints the entire file in reverse order. If the file is larger than 20,480 bytes, the -r flag displays only the last 20,480 bytes.

종료 상태

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

This command returns the following exit values:

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

예제

  1. notes 파일의 마지막 10줄을 표시합니다.
bash
tail notes
  1. notes 파일 끝에서부터 읽기 시작할 줄 수를 지정합니다.
bash
tail -n 20 notes
  1. notes 파일을 200번째 바이트부터 한 쪽씩 표시합니다.
bash
tail -c +200 notes | pg
  1. 파일이 늘어나는 것을 지켜봅니다. accounts 파일의 마지막 10줄을 표시한 뒤, 파일에 줄이 더해지는 대로 계속 표시합니다. Ctrl-C를 누를 때까지 이어집니다.
bash
tail -f accounts
영어 원문
  1. To display the last 10 lines of the notes file, enter: tail notes

  2. To specify the number of lines to start reading from the end of the notes file, enter:

tail -n 20 notes

  1. To display the notes file a page at a time, beginning with the 200th byte, enter:

tail -c +200 notes | pg

  1. To follow the growth of a file, enter:

tail -f accounts

This displays the last 10 lines of the accounts file. The tail command continues to display lines as they are added to the accounts file. The display continues until you press the Ctrl-C key sequence to stop it.

파일

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

관련 명령어: dd, head, pg

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

Related information:

  • dd command
  • head command
  • pg command
  • Files command
  • Input and output redirection

리눅스(GNU)와 다른 점

항목 AIX 5.3·6.1 GNU tail
-r 거꾸로 출력(최대 20,480바이트) 없음(tac을 씀)
-m·-b·-k 문자·512바이트·1KB 단위 위치 없음
파일 수 구문상 파일 하나 여러 파일을 받아 머리글과 함께 출력
-f의 대상 열어 둔 파일을 계속 읽음 -F·--follow=name으로 이름이 바뀐 로그도 다시 엶

AIX 5.3·6.1 문서에는 -F, --retry, --pid, -q·-v 같은 GNU 플래그가 없습니다.