如果你想查看某個命令所在位置, 該如何?
有兩個命令可以幫助你解決問題: which
,whereis
which
DESCRIPTION
The which utility takes a list of command names and searches the path for each executable file that would be run had these commands actually been invoked.
.
The following options are available:
-a List all instances of executables found (instead of just the first one of each).
-s No output, just return 0 if any of the executables are found, or 1 if none are found.
Some shells may provide a builtin which command which is similar or identical to this utility. Consult the builtin(1) manual page.
which
從path中收索可執(zhí)行命令的文件, 輸出真實的被執(zhí)行的文件的路徑.
默認輸出第一個文件的路徑, -a輸出所有文件(在path中收索到的)的路徑.
如: which java
, 輸出如下:
/usr/bin/java
which -a java
, 則輸出如下:
/usr/bin/java /Library/Java/JavaVirtualMachines/jdk1.8.0_77.jdk/Contents/Home/bin/java
whereis
The whereis utility checks the standard binary directories for the specified programs, printing out the paths of any it finds.
The path searched is the string returned by the sysctl(8) utility for theuser.cs_path
string.
whereis
收索的是給定名稱的可執(zhí)行程序, 然后輸出此程序的文件路徑.
如whereis grep
, 可以輸出grep程序所在路徑:
/usr/bin/grep
如果你的機器上安裝了某個程序的多個版本(jdk, python, ruby.....), 那么用上述命令可以查看當前版本程序所在的位置.