shell命令--which


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:查看命令所在絕對路徑,比如 man

which man

范例2:which 查找的目錄,PATH 變量的值

echo $PATH

范例3:查找有別名的命令時會列出具體的別名信息

which which

​ 用 which 去找出 which,結果會有兩個 which ,其中一個是 alias 這就是所謂的命令別名

范例4:Bash 內建一些命令無法查找到,比如 history

which history

history 這個常用的命令找不到,這是因為 historybash 內建的命令! 但是 which 默認是找 PATH 內所規范的目錄,所以當然找不到!

『MineGi有話說』:快來掃一掃下面鏈接的二維碼,加入我們吧!


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM