linux或类linux系统下如何查看命令所在位置?

2016-05-04  本文已影响783人  元亨利贞o

如果你想查看某个命令所在位置, 该如何?

有两个命令可以帮助你解决问题: which,whereis

  1. 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中收索可执行命令的文件, 输出真实的被执行的文件的路径.
默认输出第一个文件的路径, -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

  1. 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 the user.cs_path string.

whereis 收索的是给定名称的可执行程序, 然后输出此程序的文件路径.

whereis grep, 可以输出grep程序所在路径:

/usr/bin/grep

如果你的机器上安装了某个程序的多个版本(jdk, python, ruby.....), 那么用上述命令可以查看当前版本程序所在的位置.


上一篇下一篇

猜你喜欢

热点阅读