shell命令--which
0、which命令的專屬圖床
點此快速打開文章【圖床_shell命令which】
1、which命令的功能說明
which命令的作用是在PATH變量指定的路徑中搜索某個系統命令的位置並且返回第一個搜索結果。也就是說使用which命令就可以看到某個系統命令是否存在以及執行的到底是哪一個位置的命令
2、which命令的語法格式
SYNOPSIS which [options] [--] programname [...]
3、which命令的選項說明
- --version, -[vV]:顯示版本信息
- --help:顯示幫助信息
- --skip-dot:Skip directories in PATH that start with a dot.
- --skip-tilde:Skip directories in PATH that start with a tilde.
- --show-dot:Don't expand a dot to current directory in output.
- --show-tilde:Output a tilde for HOME directory for non-root.
- --tty-only:Stop processing options on the right if not on tty.
- --all, -a:查找全部匹配的,而非第一個
- --read-alias, -i:Read list of aliases from stdin.
- --skip-alias:Ignore option --read-alias; don't read stdin.
- --read-functions:Read shell functions from stdin.
- --skip-functions:Ignore option --read-functions; don't read stdin.
4、which命令的實踐操作
范例1:查看命令所在絕對路徑,比如
manwhich man
范例2:
which查找的目錄,PATH變量的值echo $PATH
范例3:查找有別名的命令時會列出具體的別名信息
which which 用
which去找出which,結果會有兩個which,其中一個是alias這就是所謂的命令別名
范例4:
Bash內建一些命令無法查找到,比如historywhich history
history這個常用的命令找不到,這是因為history是bash內建的命令! 但是which默認是找PATH內所規范的目錄,所以當然找不到!
『MineGi有話說』:快來掃一掃下面鏈接的二維碼,加入我們吧!
