which/whereis 差异

mk1*_*k12 133 unix terminal path which

which和 和有whereis什么区别?

Den*_*aia 154

学习whereiswhich使用whatis怎么样?

$  whatis which
which                (1)  - shows the full path of (shell) commands

$  whatis whereis
whereis              (1)  - locate the binary, source, and manual page files for a command
Run Code Online (Sandbox Code Playgroud)

基本上,whereis搜索“可能有用”的文件,而which只搜索可执行文件。

我很少用whereis。另一方面,which非常有用,特别是在脚本中。which是以下问题的答案:此命令从何而来?

$  which ls
/bin/ls

$  whereis ls
ls: /bin/ls /usr/share/man/man1p/ls.1p.bz2 /usr/share/man/man1/ls.1.bz2
Run Code Online (Sandbox Code Playgroud)


小智 27

whereis 搜索指定命令的标准 *nix 位置。

which搜索特定于用户的 PATH(可能包括 whereis 搜索的一些位置,可能不包括其他位置 -whereis如果您已添加到 PATH ,它还可能包括一些不搜索的位置)

  • 哦,哈哈,每当我出于某种原因看到它时,我一直认为堆栈溢出正在审查 unix 中的 U.. (11认同)
  • Unix、Linux 等(Mac OS X 属于等) (3认同)

小智 6

引用他们的手册页:

哪里

whereis 定位指定文件的源/二进制和手册部分。

例如 :

$ whereis php
php: /usr/bin/php /usr/share/php /usr/share/man/man1/php.1.gz
Run Code Online (Sandbox Code Playgroud)

即,“php”可执行文件和其他一些东西(如手册页)。


并且其中

它返回将在当前环境中执行的文件的路径名

例如 :

$ which php
/usr/bin/php
Run Code Online (Sandbox Code Playgroud)

即,只有“php”可执行文件。