[Linux] which, whereis, whatis, type, hash 명령어

  • xmoon
    (xmoon)
  • xmoon's Avatar 이 글의 작성자
  • Offline
  • Newbie
  • Newbie
더보기
28 Aug 2016 20:25 - 28 Aug 2016 21:16 #1160 작성자: xmoon
xmoon 님의 글: [Linux] which, whereis, whatis, type, hash 명령어
which, whereis, whatis 명령어 간단히 정리합니다.

which - shows the full path of (shell) commands.
- which 명령어는 PATH 환경변수에 정의된 디렉토리를 검색하여, 해당 명령어가 어느 디렉토리에 위치하고 있는지 알려줍니다.

- java 명령어 위치를 찾는 예제
# echo $PATH
/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin:/usr/local/jdk1.6.0_45/bin
# which java
/usr/bin/java

whereis - locate the binary, source, and manual page files for a command
- whereis 명령어는 명령어가 위치한 경로, 매뉴얼 파일이 있는 경로 등이 검색 가능합니다.
# whereis java
java: /usr/bin/java /etc/java /usr/lib/java /usr/share/java /usr/share/man/man1/java.1.gz

whatis - search the whatis database for complete words.
whatis는 명령어의 단순한 설명을 출력합니다. 매뉴얼파일의 NAME에 있는 설명을 출력합니다.
# whatis java
java                 (1)  - Launches a Java application
java [java-java-1]   (1)  - Launches a Java application

# whatis find - 
find                 (1)  - search for files in a directory hierarchy

type - With no options, indicate how each name would be interpreted if used as a command name.
# type java
java is /usr/bin/java
# type find
find is /bin/find

hash - For each name, the full file name of the command is determined by searching the directories in $PATH and remembered.


성능 비교 - which, type, hash
# time bash -c 'for((i=0;i<10000;i++));do which perl; done >/dev/null'
0.51s user 1.43s system 28% cpu 6.747 total
# time bash -c 'for((i=0;i<10000;i++));do hash perl; done'
0.29s user 0.41s system 98% cpu 0.718 total
# time bash -c 'for((i=0;i<10000;i++));do type perl; done >/dev/null'
0.25s user 0.24s system 98% cpu 0.498 total

10,000 번 돌렸을때는 type, hash 가 10배이상 빠르네요 ~

hash 보다는 type이 약간 빠르게 나오고,

type의 경우
검색 범위는 예약어(if, for,,,), 함수, alias 등까지 검색되어 type이 가능 범위가 넓네요 ~
더보기
29 Aug 2016 20:26 #1167 작성자: netrojoke
netrojoke 님의 답글: [Linux] which, whereis, whatis, type, hash 명령어
와! 성능 테스트까지.. 정말 꿀팁이네요.
더보기
11 Mar 2021 01:39 - 14 Mar 2021 17:50 #5217 작성자: yanmaneee
yanmaneee 님의 답글: [Linux] which, whereis, whatis, type, hash 명령어
리눅스는 컴퓨터 OS 커널의 일종인 리눅스 커널, 또는 리눅스 커널을 사용하는 운영 체제를 가리키는 말이기도 하다. GNU 쪽 사람들은 리눅스는 커널일 뿐이고, 이 커널을 가져다가 GNU 프로그램들을 올려 만든 운영 체제는 GNU/Linux라고 이야기하며 이런 명칭에 민감하게 반응하는 경우도 있다. 소스 코드가 공개되어 있는 대표적인 오픈 소스 소프트웨어다. 컴퓨터 역사상 가장 많은 참여자가 관여하고 있는 오픈 소스 프로젝트다. 모바일 운영 체제로 유명한 안드로이드 역시 리눅스 커널을 가져다 쓰고 있다.

namu.wiki/w/%EB%A6%AC%EB%88%85%EC%8A%A4
Time to create page: 0.055 seconds
Powered by Kunena Forum