1 minute read

Linux의 실행 파일 경로를 확인하는 방법

Linux에서 python을 실행할 때 우리는 당연하게도 python이라는 명령어를 CLI창에 입력합니다.
일반적으로 사용하는 python같은 linux command는 보통 환경변수로 잡혀 있고, 실제 파일(binary나 script) 위치는 다른 곳에 있습니다.
whichwhereis command는 실제 파일 위치를 찾아서 알려주는 command입니다.

which

which command는 환경 변수(environment variable)인 $PATH를 기초로 경로를 검색 및 출력해줍니다.
만약 환경 변수 $PATH 내에 입력한 command가 존재하지 않는다면, 해당 command의 경로는 출력되지 않습니다.

  • Usage
    which (option) [command/file name]
    
  • Option

    Option Description
    -a 입력한 command나 file name과 일치하는 모든 경로를 출력
  • Example
    $ which ls
    /usr/bin/ls
    
    $ which -a ls
    /usr/bin/ls
    /bin/ls
    


whereis

whereis command는 standard Linux 경로(/bin, /etc, /usr 등)와 환경 변수 $PATH 및 $MANPATH의 내부 목록을 검색합니다.
또한 whereis는 실행 파일 뿐만 아니라 source file, menual까지 대상으로 합니다.

  • Usage
    whereis (option) [command/file name]
    
  • Option

    Option Description
    -b binary를 search
    -m manual을 search
    -s soruce file을 search
    -u 특정 파일을 제외
    -B list binary file의 위치를 제한(각 directory는 공백으로 구분), -f option과 함께 사용
    -M list menual page의 위치를 제한(각 directory는 공백으로 구분), -f option과 함께 사용
    -S list 원본 file의 위치를 제한(각 directory는 공백으로 구분), -f option과 함께 사용
    -f -B, -M, -S option에 directory를 지정한 다음, 이 option에서 file명을 지정
    -l file을 조회하는 경로(디렉토리) 목록을 출력
    -v version 정보 출력
  • Example
    $ whereis python
    python: /usr/bin/python3.9 /usr/bin/python3.8-config /usr/bin/python3.8 /usr/lib/python3.9 /usr/lib/python2.7 /usr/lib/python3.8 /etc/python3.9 /etc/python3.8 /usr/local/lib/python3.9 /usr/local/lib/python3.8 /usr/include/python3.8
    

Leave a comment