리눅스의 man 명령어: 매뉴얼 보기

이 포스트에서는 리눅스에서 명령어별로 매뉴얼을 보는 man 명령어에 대해 포스팅합니다.
리눅스마스터 1급 2차 자격시험에 자주 사용하게 되는 명령어이며, 실무에서도 가끔 사용하는 명령어입니다.

man 명령어는 manual의 약자로, 특정 명령어에 대한 매뉴얼을 보는 명령어입니다. /usr/bin 경로에 설치된 프로그램 형태의 명령어나 설치된 패키지 중 매뉴얼을 제공하는 패키지의 명령어는 이 man 명령어로 매뉴얼을 읽을 수 있습니다.

man 명령어의 기본적인 사용법은 다음과 같습니다.

$ man (매뉴얼을 확인할 명령어)[.섹션번호]

섹션 번호는 매뉴얼을 확인할 명령어보다 먼저 적고 뒤에 공백을 써도 됩니다. 섹션 번호는 생략 가능하며 생략시 숫자가 가장 작은 번호가 자동으로 지정됩니다. 섹션 번호의 의미는 다음과 같습니다.

  1. 실행 가능한 프로그램이나 셸 명령어
  2. 시스템 콜
  3. 라이브러리 콜
  4. 특수한 파일 (대개 /dev 경로에 있음)
  5. 파일 포맷과 규약 (예: /etc/passwd)
  6. 게임
  7. 기타
  8. 시스템 관리 명령어 (대개 root 권한 필요)
  9. 커널 루틴 (단, 이는 표준이 아님)

여기서,

$ man cat

위와 같이 cat 명령어의 매뉴얼을 보는 명령을 내리면

CAT(1)                           User Commands                          CAT(1)

NAME
       cat - concatenate files and print on the standard output

SYNOPSIS
       cat [OPTION]... [FILE]...

DESCRIPTION
       Concatenate FILE(s) to standard output.

       With no FILE, or when FILE is -, read standard input.

       -A, --show-all
              equivalent to -vET

       -b, --number-nonblank
              number nonempty output lines, overrides -n

       -e     equivalent to -vE

       -E, --show-ends
              display $ at end of each line

 Manual page cat(1) line 1 (press h for help or q to quit)

(※편의상 일부만 보여드립니다. 실제로는 보여드리는 것보다 내용이 더 많습니다.)
위와 같은 화면이 나옵니다. 위의 화면에서 방향키를 누르면 스크롤, h 키를 누르면 도움말을 볼 수 있고 q 키를 누르면 끝내고 명령줄로 돌아갑니다.
또한, 매뉴얼 페이지에서 특정 단어를 검색하고자 할 때는 슬래시(/) 키를 누르고 검색할 문자열을 입력합니다.(예: /user – ‘user’라는 단어를 검색) 문자열 검색에 정규 표현식을 사용할 수 있습니다.

$ man printf.3

위와 같이 입력하면(man 3 printf 식으로 써도 가능) printf 명령어의 3번 섹션에 해당하는 ‘시스템 콜’ 부분을 보여줍니다.

$ man -a printf

위와 같은 형식으로 입력하면 모든 섹션을 보여줍니다. 우선 첫 번째 섹션부터 보여주고 나갈 때 다음 섹션이 있으면 해당 섹션을 볼 것인지 묻습니다. 보려면 Enter 키를, 생략하려면 Ctrl-D 키를, 종료하려면 Ctrl-C 키를 누릅니다.

또한, -k 옵션을 줄 수도 있는데, 이 옵션은 키워드로 매뉴얼 검색을 할 때 사용합니다.

$ man -k printf
asprintf (3)         - print to allocated string
dprintf (3)          - formatted output conversion
fprintf (3)          - formatted output conversion
fwprintf (3)         - formatted wide-character output conversion
printf (1)           - format and print data
printf (3)           - formatted output conversion
snprintf (3)         - formatted output conversion
sprintf (3)          - formatted output conversion
swprintf (3)         - formatted wide-character output conversion
vasprintf (3)        - print to allocated string
vdprintf (3)         - formatted output conversion
vfprintf (3)         - formatted output conversion
vfwprintf (3)        - formatted wide-character output conversion
vprintf (3)          - formatted output conversion
vsnprintf (3)        - formatted output conversion
vsprintf (3)         - formatted output conversion
vswprintf (3)        - formatted wide-character output conversion
vwprintf (3)         - formatted wide-character output conversion
wprintf (3)          - formatted wide-character output conversion
XtAsprintf (3)       - memory management functions

위와 같이 printf 키워드로 검색해 보면 해당 키워드의 매뉴얼 페이지들이 뜨는 것을 볼 수 있습니다.

참고: cd 등 내부 명령어는 man 명령어로 매뉴얼을 볼 수 없는데, 해당 명령어에 대한 도움말을 보려면 help 명령어를 이용합니다.

“리눅스의 man 명령어: 매뉴얼 보기”의 1개의 생각

답글 남기기

이메일 주소는 공개되지 않습니다.