Linux Command Line - 도움말 확인하기

toastedEevee·2024년 7월 10일

Linux Command Line

목록 보기
2/7
post-thumbnail

man pages


메뉴얼 페이지(줄여서 맨 페이지)는 UNIX 계열 운영체제 대부분에서 사용할 수 있는 내장된 문서들이다.

운영체제마다 구체적인 내용은 다르지만, 이 명령어를 실행해서 다른 명령어에 대해 더 많은 정보를 알아보거나, 리눅스, 혹은 전반적인 시스템에 관한 정보를 찾아볼 수 있다.

man ncal

아래와 같이 ncal에 대한 다양한 정보를 표시한다.

CAL(1)                                                                                   General Commands Manual                                                                                  CAL(1)

NAME
     cal, ncal – displays a calendar and the date of Easter

SYNOPSIS
     cal [-3hjy] [-A number] [-B number] [[month] year]
     cal [-3hj] [-A number] [-B number] -m month [year]
     ncal [-3hjJpwy] [-A number] [-B number] [-s country_code] [[month] year]
     ncal [-3hJeo] [-A number] [-B number] [year]
     ncal [-CN] [-H yyyy-mm-dd] [-d yyyy-mm]

DESCRIPTION
     The cal utility displays a simple calendar in traditional format and ncal offers an alternative layout, more options and the date of Easter.  The new format is a little cramped but it makes a
     year fit on a 25x80 terminal.  If arguments are not specified, the current month is displayed.

     The options are as follows:

     -h      Turns off highlighting of today.

     -J      Display Julian Calendar, if combined with the -e option, display date of Easter according to the Julian Calendar.

     -e      Display date of Easter (for western churches).

     -j      Display Julian days (days one-based, numbered from January 1).

     -m month
             Display the specified month.  If month is specified as a decimal number, it may be followed by the letter ‘f’ or ‘p’ to indicate the following or preceding month of that number,
             respectively.

     -o      Display date of Orthodox Easter (Greek and Russian Orthodox Churches).

     -p      Print the country codes and switching days from Julian to Gregorian Calendar as they are assumed by ncal.  The country code as determined from the local environment is marked with an
             asterisk.

     -s country_code
             Assume the switch from Julian to Gregorian Calendar at the date associated with the country_code.  If not specified, ncal tries to guess the switch date from the local environment or
             falls back to September 2, 1752.  This was when Great Britain and her colonies switched to the Gregorian Calendar.

     -w      Print the number of the week below each week column.

     -y      Display a calendar for the specified year.

     -3      Display the previous, current and next month surrounding today.

     -A number
             Display the number of months after the current month.

     -B number
             Display the number of months before the current month.

     -C      Switch to cal mode.

     -N      Switch to ncal mode.

     -d yyyy-mm
             Use yyyy-mm as the current date (for debugging of date selection).

     -H yyyy-mm-dd
             Use yyyy-mm-dd as the current date (for debugging of highlighting).

     A single parameter specifies the year (1–9999) to be displayed; note the year must be fully specified: “cal 89” will not display a calendar for 1989.  Two parameters denote the month and year;
:
✅ 문서 읽기를 종료하려면 `q`를 입력하면 된다.

Less Commands


‘less’는 파일의 내용을 터미널에서 페이지 단위로 볼 수 있게 해주는 명령어이다. ‘less’ 명령어는 대형 파일을 한 번에 모두 로드하지 않고, 필요한 부분만 로드하여 메모리 사용을 최소화하는 방식으로 작동한다. 이로 인해, 파일의 특정 부분을 빠르게 탐색할 수 있다.

man 명령어는 이 ‘less’를 기본 페이저(pager)로 사용한다.

탐색 명령어동작
스페이스바 / f(Foward)다음 페이지로 가기
b(Back)이전 페이지로 가기
h(Help)도움말 페이지(키보드 명령어와 탐색 방법에 대한 정보)
qless를 종료
G파일의 끝으로 이동
g파일의 시작으로 이동

man pages contents


일반적으로, 각 man 페이지는 다음과 같은 형식을 따른다.

  • 명령어의 제목 / 이름과 짧은 설명 : 명령어의 이름과 그 목적에 대한 짧은 설명이 포함된다.
  • 명령어의 문법 개요 : 명령어의 사용법과 필수 또는 선택적 인수들에 대한 문법이 설명된다.
  • 명령어의 옵션 설명 : 명령어에 사용할 수 있는 모든 옵션과 그 설명이 포함된다.

man pages synopsis

대괄호 안의 목록들은 선택적 인수이다.


ncal [-3hJeo] [-A number] [-B number] [year]
ls [OPTION]... [FILE]...

필수 피연산자는 대괄호로 감싸져 있지 않다.


cp [OPTION]… SOURCE DEST

‘SOURCE’와 ‘DEST’는 필수 인수로, 복사할 원본 파일과 대상 파일을 지정해야 한다.

Manual Sections


메뉴얼 페이지는 여러 섹션으로 나뉘어 있으며, 각 섹션은 특정 유형의 정보나 명령어를 다룬다.

  1. General Commands(User Commands) : 시스템에서 일반적으로 사용되는 사용자 명령어 (예: ‘ls’, ‘cp’, ‘mv’)
  2. System Calls : 커널이 제공하는 함수 (예: ‘open’, ‘read’, ‘write’)
  3. Library Functions : 표준 C 라이브러리 함수 (예: ‘printf’, ‘malloc’, ‘exit’)
  4. Special files and Drivers : ‘/dev’ 디렉토리에 있는 파일들과 장치 드라이버
  5. File formates and Convertions : 파일 포맷과 규약에 대한 정보 (예: ‘/etc/passwd’, ‘crontab’)
  6. Games : 게임과 관련된 명령어
  7. Macro packages and Miscellaneous : 매크로 패키지와 기타 문서 (예: ‘man’, ‘groff’)
  8. System administration Commands : 시스템 관리자가 사용하는 명령어 (예: ‘mount’, ‘ifconfig’)
  9. Kernel routines : 커널 내부 함수
✅ 특정 섹션을 지정하지 않으면 기본적으로 가장 먼저 찾은 매뉴얼 페이지를 표시한다. 예를 들어, `man printf`를 입력하면 기본적으로 섹션 1(일반 명령어)에서 `printf` 명령어를 찾고, 없다면 다른 섹션을 검색한다.

man -k [검색어]

apropos 명령어와 동일한 역할을 하며, 메뉴얼 페이지의 제목과 설명에서 주어진 키워드를 검색한다. 특정 키워드와 관련된 모든 명령어, 함수, 파일, 라이브러리 등을 찾을 수 있다.

man -k network
ifconfig (8)        - configure network interface parameters
netstat (1)         - show network status
ping (8)            - send ICMP ECHO_REQUEST to network hosts

추가 옵션

  • man -f [명령어] : 특정 명령어에 대한 요약 정보를 표시함(’whatis’와 동일)
  • man [섹션 번호] [명령어] : 특정 섹션에서 명령어의 메뉴얼 페이지를 표시함( 예 - ‘man 3 printf’)

Types Of Commands


type 명령어는 Unix 및 Unix-like 운영 체제에서 사용자가 입력한 명령어가 내부 명령어인지, 외부 명령어인지, 별칭인지, 함수인지 등 명령어의 유형과 위치를 확인하는 데 사용된다.

  • 사용법
 type [옵션] [명령어]
  • 옵션
    • -a : PATH 변수에 설정된 모든 경로를 검색하여 명령어의 모든 위치를 출력
    • -t : 명령어의 유형만 출력
    • -p : 명령어의 위치만 출력
    • -P : PATH 변수에 설정된 경로에서 실행 파일의 위치만 검색하여 출력(명령어의 유형이 실행 파일일 경우에만 위치를 출력).
    • 옵션 없이 사용하면, 해당 명령어의 유형과 위치를 모두 출력한다.
  • 예시
    alias myls='ls -la'
    1. type -a 사용

      type -a myls
      myls is an alias for ls -la
      myls is /usr/bin/ls

      myls가 별칭(alias)이고, /usr/bin/ls 경로에 있는 실행 파일임을 모두 보여준다.


    2. type -P 사용

      type -P myls
      /usr/bin/ls

      myls의 실행 파일 경로만을 보여주고, 별칭은 무시된다.

1. 실행 가능한 프로그램(Executable Program) / 실행 파일

실행 가능한 프로그램은 보통 /bin, /usr/bin, 또는 /usr/local/bin 디렉토리에 저장된다. 이러한 프로그램들은 컴파일된 이진 파일(컴파일된 바이너리 파일)로, 운영 체제에서 직접 실행될 수 있다.

  • 예시 : ls, cp, mkdir
  • 특징 : 특정 위치에 저장된 독립적인 파일로서, 커널이 이를 직접 실행함.
$ type ls
ls is /bin/ls

2. 쉘 내장 명령어(Built-in Shell Command)

쉘 내장 명령어는 쉘의 일부로 포함된 명령어이다. 즉, 이 명령어들은 외부 프로그램이 아니기 때문에 새로운 프로세스를 생성하지 않고도 즉시 실행될 수 있다. 따라서 보통 더 빠르게 실행되며, 쉘의 내부 상태를 조작할 수 있다.

  • 예시 : cd, pwd, echo, alias, export
  • 특징 : 쉘의 일부로 컴파일되어 있으며, 쉘 프로세스가 이를 직접 처리함.
$ type cd
cd is a shell builtin

3. 쉘 함수(Shell Function)

쉘 함수는 쉘 스크립트 내에서 정의된 함수로, 특정 작업을 수행하는 명령어 집합이다. 사용자는 쉘 스크립트나 쉘 환경 내에서 필요한 기능을 함수로 정의할 수 있다.

  • 예시
    $ my_function() { echo "This is a shell function"; }
    $ type my_function
    my_function is a function
    my_function () 
    { 
        echo "This is a shell function"
    }
  • 특징 : 쉘 스크립트 내에서 정의되며, 함수 이름을 통해 호출할 수 있다.

4. 별칭(Alias)

별칭은 긴 명령어나 복잡한 명령어의 단축형을 정의한 것이다. 별칭을 사용하면 자주 사용하는 명령어를 더 쉽게 입력할 수 있다.

  • 예시 : alias ll='ls -l'
  • 특징 : 별칭은 쉘 세션 내에서 정의되며, 일반적으로 .bashrc 또는 .bash_profile 파일에 정의하여 쉘 시작 시 자동으로 로드되도록 한다.
$ alias ll='ls -l'
$ type ll
ll is aliased to `ls -l'

which

명령어의 경로를 찾아 출력한다. 실행 파일이 시스템의 어느 경로에 위치해 있는지를 확인하는 데 사용된다. which 명령어는 PATH 환경 변수에 설정된 디렉토리에서 실행 파일을 검색한다.

  • 사용법
which [옵션] [명령어]
  • 예시
which ls

[출력] - ls 명령어의 실행 파일이 /bin/ls 경로에 있음을 나타냄.

/bin/ls

주요 옵션

-a : PATH에 설정된 모든 경로를 검색하여, 해당 명령어에 대한 모든 위치를 출력한다. 기본적으로는 첫 번째로 발견된 경로만 출력한다.

  • 예시
which -a python

[출력]

/usr/bin/python
/usr/local/bin/python

활용

  • 명령어 위치 확인: 특정 명령어가 시스템의 어느 위치에 설치되어 있는지 확인할 때 사용함.
  • PATH 설정 문제 해결: PATH 환경 변수에 올바른 경로가 설정되어 있는지 확인하고 문제를 해결할 때 유용함.
  • 여러 버전 확인: 동일한 명령어가 여러 경로에 설치된 경우, 실제로 사용되는 버전을 확인할 수 있다.

PATH 환경 변수

PATH 환경 변수는 쉘이 실행 파일을 찾을 때 검색할 디렉토리들의 목록을 저장하고 있다. 이 변수에 설정된 디렉토리들은 콜론(:)으로 구분된다. 예를 들어, 다음과 같은 PATH 설정이 있다고 가정해 보자.

echo $PATH
/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin

이 경우, PATH 변수에는 /usr/local/bin, /usr/bin, /bin, /usr/sbin, /sbin 디렉토리가 포함되어 있다.

which 명령어의 동작 방식

which 명령어는 사용자가 입력한 명령어가 PATH 환경 변수에 나열된 디렉토리들 중 어디에 위치해 있는지 찾는다. 예를 들어, ls 명령어를 찾으려면 다음과 같이 실행할 수 있다.

which ls

which 명령어는 다음 순서로 동작한다.

  1. PATH 변수에 나열된 첫 번째 디렉토리(/usr/local/bin)에서 ls라는 실행 파일이 있는지 확인한다.
  2. 만약 첫 번째 디렉토리에 ls 파일이 없다면, 두 번째 디렉토리(/usr/bin)에서 ls 파일을 찾는다.
  3. 이 과정을 PATH 변수에 나열된 모든 디렉토리에 대해 반복한다.

요약

  • PATH 환경 변수는 쉘이 명령어를 찾을 때 검색할 디렉토리 목록을 정의한다.
  • which 명령어는 PATH 변수에 설정된 디렉토리들을 순서대로 검색하여, 사용자가 입력한 명령어의 실행 파일을 찾는다.
  • 첫 번째로 발견된 경로를 출력하여, 명령어가 시스템의 어느 위치에 있는지 알려준다.

Help


쉘 내장 명령어의 도움말을 출력하는 명령어

help cd
cd: cd [-L|-P] [dir]
    Change the current directory to DIR.  The variable $HOME is the
    default DIR.  The variable CDPATH defines the search path for
    the directory containing DIR.  Alternative directory names in CDPATH
    are separated by a colon (:).  A null directory name is the same as
    the current directory, i.e. `.'.  If DIR begins with a slash (/),
    then CDPATH is not used.  If the directory is not found, and the
    shell option `cdable_vars' is set, then try the word as a variable
    name.  If that variable has a value, then cd to the value of that
    variable.  The -P option says to use the physical directory structure
    instead of following symbolic links; the -L option forces symbolic links
    to be followed.
💡 less 프로그램이 아니기 때문에 스크롤 등에 사용했던 단축키도 사용할 수 없다. `man` 으로 도움말을 볼 수 없는 명령어는 `help` 로 도움말을 확인해 보면 된다.
help export
export: export [-nf] [name[=value] ...] or export -p
    NAMEs are marked for automatic export to the environment of
    subsequently executed commands.  If the -f option is given,
    the NAMEs refer to functions.  If no NAMEs are given, or if `-p'
    is given, a list of all names that are exported in this shell is
    printed.  An argument of `-n' says to remove the export property
    from subsequent NAMEs.  An argument of `--' disables further option
    processing.
profile
내가그린솜뭉치

0개의 댓글