which 명령어 (AIX 5.3·6.1)

핵심 정리

  • 명령 이름을 주면, 그 이름으로 실행될 파일의 경로를 찾아 보여 줍니다.
  • 별칭(alias)이면 펼친 뒤 사용자의 경로에서 찾습니다.
  • 별칭과 경로는 홈 디렉터리의 .cshrc에서 가져옵니다. .cshrc가 없거나 거기에 경로가 없으면 환경의 PATH를 씁니다.
  • 별칭이 여러 단어로 펼쳐지거나 경로에서 실행 파일을 찾지 못하면 진단 메시지를 냅니다.
  • Korn 셸에서는 whence(또는 whence -v, type)가 더 자세히 알려 주며, ksh의 별칭과 함수는 which가 모릅니다.
  • AIX 5.3과 6.1 문서의 내용이 같습니다.
항목 내용
버전 AIX 5.3, AIX 6.1 (두 버전 내용 같음)
원문 IBM Commands Reference — 5.3 Volume 6, 6.1 Volume 6
파일 /usr/bin/which, $HOME/.cshrc
관련 명령어 whence(ksh), type, csh

목적

명령의 실행 파일을 찾습니다.

영어 원문

Locates a program file, including aliases and paths.

구문

text
which [ Name ... ]

설명

which 명령은 프로그램 이름 목록을 받아, 그 이름을 명령으로 줄 때 실행될 파일을 찾습니다. 인수가 별칭이면 펼친 뒤 사용자의 경로를 따라 찾습니다. 별칭과 경로는 사용자 홈 디렉터리의 .cshrc 파일에서 가져옵니다. .cshrc 파일이 없거나 그 안에 경로가 정의돼 있지 않으면 사용자 환경에 정의된 경로를 씁니다.

이름이 둘 이상의 단어로 된 별칭이거나, 그 이름의 실행 파일을 경로에서 찾지 못하면 진단 메시지를 냅니다.

Korn 셸에서는 whence 명령으로 더 자세한 보고를 얻을 수 있습니다.

영어 원문

The which command takes a list of program names and looks for the files that run when these names are given as commands. The which command expands each argument, if it is aliased, and searches for it along the user's path. The aliases and paths are taken from the .cshrc file in the user's home directory. If the .cshrc file does not exist, or if the path is not defined in the .cshrc file, the which command uses the path defined in the user's environment.

A diagnostic is given if a name is aliased to more than a single word or if an executable file with the argument name is not found in the path.

In the Korn shell, you can use the whence command to produce a more verbose report.

예제

명령 이름 lookup에 해당하는 실행 파일을 찾습니다.

bash
which lookup
영어 원문

To find the executable file associated with a command name of lookup: which lookup

파일

파일 설명
$HOME/.cshrc 별칭과 경로 값을 가져오는 곳입니다.

관련 명령어: csh, ksh(내장 명령 whence)

영어 원문
  • $HOME/.cshrc — Contains the source of aliases and path values.

Related information:

  • Korn shell or POSIX shell built-in commands
  • csh command
  • ksh command

리눅스(GNU)와 다른 점

AIX의 which는 C 셸 방식이라 .cshrc를 읽고, ksh에서 정의한 별칭이나 함수는 알지 못합니다. 리눅스의 GNU which는 PATH만 보며 -a(모든 일치)를 지원합니다. ksh·bash 어디서나 쓸 수 있는 방법은 command -v 이름이나 type 이름입니다.