which命令詳解

NAME
which - show the full path of (shell) commands 顯示命令的完整路徑。
SYNOPSIS

                which   [options]  [--]  programname [...]

DESCRIPTION
which takes one or more arguments. For each of its arguments it prints to stdout the full path of the executables that would have been executed when this argument had been entered at the shell prompt. It does this by searching for an executable or script in the directories listed in the environment variable PATH using the same algorithm as bash(1).
which可以帶一個或多個參數。對於每一個參數,當這個參數被鍵入到shell命令提示符中,它打印可執行文件的完整路徑到標準輸出。它用bash相同的算法(即顯示最先被搜尋到的哪一個),它在PATH環境變量列出來的目錄執行這個搜索可執行文件或者腳本文件。
實例1:查找文件、顯示命令路徑
which命令詳解
說明:
which是根據使用者所配置的PATH變量內的目錄去搜尋可運行擋的!所以,不同的PATH配置內容所找到的命令當然不一樣。
實例2:用which 去找which
which命令詳解
說明:

竟然會有兩個 which ,其中一個是 alias 這就是所謂的『命令別名』,意思是輸入 which 會等於後面接的那串命令!
實例3:找出cd這個命令
which命令詳解
說明:
cd 這個常用的命令竟然找不到?爲什麼呢?這是因爲cd是bash內建命令!但是which默認是找PATH內所包含的目錄,所以當然一定找不到。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章