我使用命令 whereis rm
$ whereis rm
/bin/rm
Run Code Online (Sandbox Code Playgroud)
然后我试试 which rm
$ which rm
/usr/local/opt/coreutils/libexec/gnubin/rm
Run Code Online (Sandbox Code Playgroud)
结果是不同的......所以rm
当我运行像这样的命令时会调用哪个rm readme
?
Denilson Sá Maia对超级用户的回答可能有用:
which
搜索特定于用户的 PATH(可能包括 whereis 搜索的一些位置,可能不包括其他位置 - 它还可能包括一些whereis
如果您已添加到 PATH不搜索的位置)。
whereis
搜索指定命令的标准 *nix 位置。Run Code Online (Sandbox Code Playgroud)$ 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
基本上,
whereis
搜索“可能有用”的文件,而which
只搜索可执行文件。我很少用
whereis
。另一方面,which
非常有用,特别是在脚本中。which
是以下问题的答案:此命令从何而来?Run Code Online (Sandbox Code Playgroud)$ which ls /bin/ls $ whereis ls ls: /bin/ls /usr/share/man/man1p/ls.1p.bz2 /usr/share/man/man1/ls.1.bz2