pg 명령어 (AIX 5.3·6.1)
https://archive.horanglab.com/posts/aix-cmd-pg
핵심 정리
- 파일을 한 화면씩 표준 출력에 씁니다. 화면마다 안내 문구(기본
:)를 내고, Enter를 누르면 다음 쪽을 보여 줍니다. - 파일을 지정하지 않거나
-를 지정하면 표준 입력을 읽습니다. 표준 출력이 터미널이 아니면cat처럼 동작합니다. - 하위 명령은 기본적으로 Enter로 끝내야 합니다(
-n을 주면 글자 하나로 바로 실행). - 위치 이동: 쪽 번호,
+N·-N(쪽),l·Nl(줄),d·-d(반 화면),$(마지막 쪽),.·Ctrl-L(다시 표시). - 검색:
/패턴/(앞으로),?패턴?·^패턴^(뒤로). 파일 이동은n·p, 저장은s 파일, 끝내기는q. -p 문자열로 안내 문구를 바꾸고(%d는 쪽 번호),+줄번호나+/패턴/으로 시작 위치를 정합니다.
| 항목 | 내용 |
|---|---|
| 버전 | AIX 5.3, AIX 6.1 (두 버전 내용 같음) |
| 원문 | IBM Commands Reference — 5.3 Volume 4, 6.1 Volume 4 |
| 파일 | /usr/bin/pg, /usr/share/lib/terminfo/*, /tmp/pg* |
| 관련 명령어 | more, cat, ed |
목적
파일을 화면에 맞게 나눠 표시합니다.
영어 원문
Formats files to the display.
구문
pg [ -Number ] [ -c ] [ -e ] [ -f ] [ -n ] [ -p String ] [ -r ] [ -s ] [ +LineNumber ] [ +/Pattern/ ] [ File ... ]
설명
pg 명령은 File 매개변수로 받은 파일 이름을 읽어, 그 파일을 한 화면씩 표준 출력에 씁니다. File 매개변수로 -(대시)를 지정하거나 옵션 없이 실행하면 표준 입력을 읽습니다. 화면마다 안내 문구가 이어지며, Enter 키를 누르면 다음 쪽을 표시합니다. pg의 하위 명령으로 파일을 되짚어 보거나 검색할 수 있습니다.
워크스테이션(터미널) 속성은 TERM 환경 변수가 지정한 터미널 형식을 terminfo 파일에서 찾아 정합니다. 기본 형식은 dumb입니다.
pg가 멈추고 안내 문구를 내면 하위 명령을 입력할 수 있습니다. 파일의 특정 위치로 화면을 옮기는 것, 글에서 패턴을 찾는 것, pg의 작업 환경을 바꾸는 것이 있습니다.
파일 안에서 위치 바꾸기
| 하위 명령 | 설명 |
|---|---|
| Page | Page 매개변수로 지정한 쪽을 표시합니다. |
+Number |
현재 쪽에 Number를 더한 쪽을 표시합니다. |
-Number |
현재 쪽에서 Number만큼 앞의 쪽을 표시합니다. |
l |
(소문자 L) 화면을 한 줄 앞으로 스크롤합니다. |
Numberl |
Number로 지정한 줄을 화면 맨 위에 표시합니다. |
+Numberl |
지정한 줄 수만큼 앞으로 스크롤합니다. |
-Numberl |
지정한 줄 수만큼 뒤로 스크롤합니다. |
d |
반 화면 앞으로 스크롤합니다. Ctrl-D도 같습니다. |
-d |
반 화면 뒤로 스크롤합니다. -Ctrl-D도 같습니다. |
| Ctrl-L | 현재 쪽을 다시 표시합니다. .(점) 하나도 같습니다. |
$ |
파일의 마지막 쪽을 표시합니다. 입력이 파이프일 때는 쓰지 않습니다. |
글에서 패턴 찾기
다음 하위 명령은 글에서 패턴을 찾습니다(ed 명령에서 설명하는 패턴도 쓸 수 있습니다). -n 플래그를 써도 언제나 줄바꿈 문자로 끝내야 합니다.
[a-z] 같은 식에서 빼기 기호는 현재 대조 순서에 따라 a부터 z까지 같은 범위를 뜻합니다. 대조 순서는 문자 범위에 쓸 동치 클래스를 정의합니다.
| 하위 명령 | 설명 |
|---|---|
[Number]/Pattern/ |
Pattern이 Number번째로 나오는 곳을 찾습니다. 현재 쪽 바로 뒤부터 현재 파일 끝까지 찾고, 처음으로 되돌아가지 않습니다. Number의 기본값은 1입니다. |
Number?Pattern?, Number^Pattern^ |
Pattern이 Number번째로 나오는 곳을 뒤로 찾습니다. 현재 쪽 바로 앞부터 현재 파일 처음까지 찾고, 끝으로 되돌아가지 않습니다. Number의 기본값은 1입니다. ^ 표기는 ?를 제대로 다루지 못하는 ADDS 100 터미널에서 쓸모가 있습니다. |
찾은 뒤에는 패턴과 일치한 줄을 화면 맨 위에 표시합니다. 검색 명령 뒤에 접미사를 붙여 표시 위치를 바꿀 수 있습니다. m은 그 뒤의 모든 하위 명령에서 일치한 줄을 화면 가운데에, b는 맨 아래에 표시합니다. t는 다시 맨 위에 표시합니다.
pg 환경 바꾸기
| 하위 명령 | 설명 |
|---|---|
[Number]n |
명령줄의 다음 파일(Number로 지정하면 그만큼 뒤의 파일)을 보기 시작합니다. Number의 기본값은 첫 번째입니다. |
[Number]p |
명령줄의 이전 파일(Number로 지정하면 그만큼 앞의 파일)을 보기 시작합니다. Number의 기본값은 첫 번째입니다. |
[Number]w |
글의 다음 창을 표시합니다. Number를 지정하면 창 크기를 그 줄 수로 정합니다. [Number]z와 같습니다. |
[Number]z |
글의 다음 창을 표시합니다. Number를 지정하면 창 크기를 그 줄 수로 정합니다. [Number]w와 같습니다. |
s File |
입력을 지정한 파일에 저장합니다. 지금 보고 있는 파일만 저장합니다. -n 플래그를 지정해도 언제나 줄바꿈 문자로 끝내야 합니다. |
h |
쓸 수 있는 하위 명령의 요약을 표시합니다. |
q, Q |
pg 명령을 끝냅니다. |
!Command |
지정한 명령을 SHELL 환경 변수에 지정한 셸로 보냅니다. 없으면 기본 셸을 씁니다. -n 플래그를 써도 언제나 줄바꿈 문자로 끝내야 합니다. |
주의
- QUIT WITH DUMP(
Ctrl-\)나 INTERRUPT(Ctrl-C)를 누르면 출력 대기열에 있던 문자가 QUIT 신호를 받을 때 버려지므로 출력 일부를 잃습니다. - 터미널의 탭이 8칸마다 설정돼 있지 않으면 예상할 수 없는 결과가 날 수 있습니다.
터미널로 출력을 보내는 중에는 언제든 QUIT WITH DUMP나 INTERRUPT를 누를 수 있습니다. 그러면 pg가 출력을 멈추고 안내 문구를 표시하며, 위의 하위 명령을 입력할 수 있습니다.
표준 출력이 워크스테이션(터미널)이 아니면 pg는 cat 명령처럼 동작하되, 파일마다 앞에 머리글을 표시합니다.
터미널 입력을 기다리는 동안 INTERRUPT를 누르면 pg가 끝납니다. 안내 문구 사이에서는 이 신호들이 현재 작업을 중단하고 안내 문구 상태로 돌아가게 합니다.
영어 원문
The pg command reads a file name from the File parameter and writes the file to standard output one screen at a time. If you specify a - (dash) as the File parameter, or run the pg command without options, the pg command reads standard input. Each screen is followed by a prompt. If you press the Enter key, another page is displayed. Subcommands used with the pg command let you review or search in the file.
To determine workstation attributes, the pg command scans the file for the workstation type specified by the TERM environment variable. The default type is dumb.
When the pg command pauses and issues a prompt, you can issue a subcommand. Some of these subcommands change the display to a particular place in the file, some search for specific patterns in the text, and others change the environment in which the pg command works.
Changing Location Within the File
The following subcommands display a selected place in the file:
- Page — Displays the page specified by the Page parameter.
+Number — Displays the page obtained by adding the Number value to the current page.-Number — Displays the page as specified by the Number value before the current page.- l — (Lowercase L) Scrolls the display one line forward.
- Numberl — Displays at the top of the screen the line specified by the Number parameter.
+Numberl — Scrolls the display forward for the specified number of lines.-Numberl — Scrolls the display backward for the specified number of lines.- d — Scrolls half a screen forward. Pressing the Ctrl-D key sequence functions the same as the d subcommand.
-d— Scrolls half a screen backward. Pressing the-Ctrl-D key sequence functions the same as the-dsubcommand.- Ctrl-L — Displays the current page again. A single . (dot) functions the same as the Ctrl-L key sequence subcommand.
$— Displays the last page in the file. Do not use this when the input is from a pipeline.- Searching for Text Patterns
The following subcommands search for text patterns in the text. (You can also use the patterns described in the ed command.) They must always end with a new-line character, even if the -n flag is used.
In an expression such as [k.a-z]k., the minus implies a range, as in a through z, according to the current collating sequence. A collating sequence defines equivalence classes for use in character ranges.
- [Number]/Pattern/ — Searches for the occurrence of the Pattern value as specified by the Number variable. The search begins immediately after the current page and continues to the end of the current file, without wraparound. The default for the Number variable is 1.
- Number?Pattern?
- NumberPattern — Searches backward for the occurrence of the Pattern value as specified by the Number variable. The searching begins immediately before the current page and continues to the beginning of the current file, without wraparound. The default for the Number variable is 1. The
^notation is useful for Adds 100 terminals which will not properly handle the?notation.
After searching, the pg command displays the line with the matching pattern at the top of the screen. You can change the position of the display by adding the m or b suffix to the search command. The m suffix displays the line with the matching pattern in the middle of the screen for all succeeding subcommands. The b suffix displays the line with the matching pattern at the bottom of the screen for all succeeding subcommands. The t suffix displays the line with the matching pattern at the top of the screen again.
Changing the pg Environment
You can change the pg command environment with the following subcommands:
- [Number]n — Begins examining the next file in the command line, as specified by the Number variable. The default for the Number variable is first.
- [Number]p — Begins examining the previous file on the command line, as specified by the Number variable. The default for the Number variable is first.
- [Number]w — Displays another window of text. If the Number variable is specified, sets the window size to the number of lines it specifies. This subcommand is the same as the [Number]z subcommand.
- [Number]z — Displays another window of text. If the Number variable is specified, sets the window size to the number of lines it specifies. This subcommand is the same as the [Number]w subcommand.
- s File — Saves the input in the specified file. Only the current file being examined is saved. This command must always end with a new-line character, even if you specify the
-nflag. - h — Displays an abbreviated summary of available subcommands.
- q or Q — Quits the pg command.
- !Command — Sends the specified command to the shell named in the SHELL environment variable. If this is not available, the default shell is used. This command must always end with a new-line character, even if the
-nflag is used. - Attention:
Some output is lost when you press the QUIT WITH DUMP (
Ctrl-\) or INTERRUPT (Ctrl-C) key sequence because any characters waiting in the output queue are purged when the QUIT signal is received.If workstation tabs are not set every eight positions, unpredictable results can occur.
At any time output is being sent to the workstation, you can press the QUIT WITH DUMP or INTERRUPT key sequence. This causes the pg command to stop sending output and displays the prompt. Then you can enter one of the preceding subcommands at the command prompt.
If standard output is not a workstation, the pg command acts like the cat command, except that a header is displayed before each file.
While waiting for workstation input, the pg command stops running when you press the INTERRUPT key sequence. Between prompts these signals interrupt the current task and place you in the prompt mode.
플래그
| 플래그 | 설명 |
|---|---|
-c |
쪽마다 커서를 처음 위치로 옮기고 화면을 지웁니다. terminfo 파일에 터미널 형식의 clear_screen 항목이 없으면 무시합니다. |
-e |
파일이 끝날 때마다 멈추지 않습니다. |
-f |
줄을 나누지 않습니다. 보통은 화면 폭보다 긴 줄을 나눕니다. |
-n |
pg 명령 글자를 입력하면 바로 처리합니다. 보통은 명령을 줄바꿈 문자로 끝내야 합니다. |
-p String |
지정한 문자열을 안내 문구로 씁니다. 문자열에 %d가 있으면 현재 쪽 번호로 바꿉니다. 기본 안내 문구는 :(쌍점)입니다. 문자열에 공백이 있으면 따옴표로 감쌉니다. |
-r |
! 하위 명령으로 셸에 나가지 못하게 합니다. |
-s |
모든 메시지와 안내 문구를 강조해 표시합니다. |
+LineNumber |
지정한 줄 번호에서 시작합니다. |
-Number |
창의 줄 수를 정합니다. 24줄 터미널에서는 기본이 23줄입니다. |
+/Pattern/ |
지정한 패턴이 처음 나오는 줄에서 시작합니다. |
영어 원문
-c— Moves the cursor to the home position and clears the screen before each page. This flag is ignored if theclear_screenfield is not defined for your workstation type in the terminfo file.-e— Does not pause at the end of each file.-f— Does not split lines. Normally, the pg command splits lines longer than the screen width.-n— Stops processing when a pg command letter is entered. Normally, commands must end with a new-line character.-pString — Uses the specified string as the prompt. If the String contains a %d value, that value is replaced by the current page number in the prompt. The default prompt is : (colon). If the specified string contains spaces, you must enclose the string in quotation marks.-r— Prevents shell escape when the "!" subcommand is used.-s— Highlights all messages and prompts.+LineNumber — Starts at the specified line number.-Number — Specifies the number of lines in the window. On workstations that contain 24 lines, the default is 23.+/Pattern/ — Starts at the first line that contains the specified pattern.
종료 상태
| 값 | 뜻 |
|---|---|
| 0 | 잘 끝났습니다. |
| 0보다 큼 | 오류가 났습니다. |
영어 원문
This command returns the following exit values:
- 0 — Successful completion.
>0— An error occurred.
예제
파일 내용을 한 쪽씩 봅니다.
pg filename
영어 원문
To look at the contents of a file one page at a time, enter: pg filename
파일
| 파일 | 설명 |
|---|---|
/usr/bin/pg |
pg 명령이 들어 있습니다. |
/usr/share/lib/terminfo/* |
터미널 형식을 정의하는 terminfo 파일이 들어 있습니다. |
/tmp/pg* |
pg 명령을 쓸 때 만드는 임시 파일입니다. |
관련 명령어: cat, ed
영어 원문
- /usr/bin/pg — Contains the pg command.
/usr/share/lib/terminfo/*— Contains the terminfo file that defines terminal types./tmp/pg*— Contains the temporary file created when using pg command.
Related information:
- cat command
- ed command
- Input and output redirection
- Shells command
- Files command
리눅스(GNU)와 다른 점
리눅스 배포판에는 pg가 없거나(util-linux에서 빠짐) 오래된 판만 남아 있는 경우가 많고, 같은 일은 보통 more나 less로 합니다. AIX에서는 pg가 기본으로 들어 있어 ls -l | pg처럼 흔히 씁니다.