command 명령어
"command"라는 명령어는 리눅스 및 다른 유닉스 기반 운영 체제에서 내장된 기본 명령어 중 하나입니다. 이 명령어는 다른 명령어를 실행하거나 특정한 환경에서 명령을 실행할 때 사용됩니다.
command 명령어의 기본 구문
command [옵션] [명령어] [인수...]
주요 옵션
- -p: 명령어를 실행할 때 PATH 환경 변수를 무시하고 실행 가능한 파일을 검색합니다.
- -V 또는 --version: command 명령어의 버전 정보를 표시합니다.
- -h 또는 --help: command 명령어의 도움말을 표시합니다.
command 명령어의 도움말 표시
$ command --help
command: command [-pVv] command [arg ...]
Execute a simple command or display information about commands.
Runs COMMAND with ARGS suppressing shell function lookup, or display
information about the specified COMMANDs. Can be used to invoke commands
on disk when a function with the same name exists.
Options:
-p use a default value for PATH that is guaranteed to find all of
the standard utilities
-v print a description of COMMAND similar to the `type' builtin
-V print a more verbose description of each COMMAND
Exit Status:
Returns exit status of COMMAND, or failure if COMMAND is not found.
command 명령어를 사용하는 일반적인 방법
1. 다른 명령어 실행
command 명령어를 사용하여 다른 명령어를 실행할 수 있습니다. 다음은 "ls" 명령어를 "command"를 사용하여 실행하는 예시입니다.
command ls
root@8a1457850710:~$ command ls
ADirectory BDirectory
위의 예시에서 "command" 다음에 실행하려는 명령어인 "ls"를 지정합니다. 이렇게 하면 "ls" 명령어가 실행됩니다.
2. 명령어 별칭 무시
command 명령어를 사용하여 명령어 별칭을 무시하고 실제 명령어를 실행할 수 있습니다. 예를 들어, "ls" 명령어가 별칭으로 설정되어 있는 경우 실제 "ls" 명령어를 실행하려면 다음과 같이 사용합니다.
command \ls
root@8a1457850710:~$ command \ls
ADirectory BDirectory
이렇게 하면 별칭이 무시되고 "/bin/ls" 명령어가 실행됩니다.
3. 환경 변수 무시
command 명령어를 사용하여 특정 환경 변수를 무시하고 명령어를 실행할 수 있습니다. 예를 들어, "PATH" 환경 변수를 무시하고 "/usr/bin/python"을 실행하려면 다음과 같이 사용합니다.
command -p /usr/bin/python
root@8a1457850710:~$ command -p /usr/bin/python
bash: /usr/bin/python: No such file or directory
root@8a1457850710:~$ command -p /usr/bin/python3
Python 3.10.6 (main, May 29 2023, 11:10:38) [GCC 11.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>>
이렇게 하면 "PATH" 환경 변수에 의존하지 않고 "/usr/bin/python"이 실행됩니다.
4. 실행 가능한 파일 검색
command 명령어를 사용하여 PATH 경로에서 실행 가능한 파일을 검색하고 실행할 수 있습니다. 이는 파일의 전체 경로를 지정하지 않고도 실행 가능한 명령어를 실행하는 데 유용합니다.
command -v python
root@8a1457850710:~$ command -v python
root@8a1457850710:~$ command -v python3
/usr/bin/python3
위 명령어는 python 명령어의 전체 경로를 표시합니다.
command 명령어는 주로 특수한 상황에서 다른 명령어를 실행하거나 명령어 별칭과 환경 변수를 무시할 때 사용됩니다. 일반적인 상황에서는 command 명령어를 직접적으로 사용할 필요는 없습니다.
'리눅스' 카테고리의 다른 글
| [draft] Zabbix에서 그래프에 한글이 깨지는 문제를 해결하는 방법 (0) | 2026.02.18 |
|---|---|
| [draft] Hashicorp Vault를 사용하여 SSH CA를 구성하고 SSH 서버와 SSH 클라이언트를 연동하는 방법 (0) | 2026.02.18 |
| [draft] jq 명령어 (0) | 2026.02.18 |
| [draft] CentOS 7에서 Apache를 소스 코드로 설치하고 HTTP/2를 활성화하는 방법 (0) | 2026.02.18 |
| [draft] Zabbix를 사용하여 syslog(messages) 로그 파일을 모니터링하는 방법 (0) | 2026.02.18 |