如何在 Ubuntu 终端中获取程序的位置?

Sal*_*Boy 2 command-line bash

如何在 Ubuntu 中获取程序的位置?例如我有Oracle,如何获取 racine(位置)的文件夹Oracle

Dav*_*ter 8

Bash 和 Dash 具有command内置命令-v,如果命令引用可执行文件,则可以使用开关显示命令的位置。对于内置命令和别名,结果是不同的。例子:

$ command -v java
/usr/bin/java
$ echo $?
0
$ command -v echo
echo
$ command -v ls
alias ls='ls -h --color=auto'
$ command -v non-existing_command; echo $?
1
Run Code Online (Sandbox Code Playgroud)

此外,从 Sh 派生的所有 shell 都知道type可以告诉您任何命令的性质的命令。

$ type java
java is /usr/bin/java
$ type ls
ls is aliased to `ls -h --color=auto'
$ type echo
echo is a shell builtin
$ type non-existing_command
bash: type: non-existing_command: not found
Run Code Online (Sandbox Code Playgroud)

如果您的 shell(例如 Bash)支持它,请type -a列出命令可能引用的所有内容:

$ type -a ls
ls is aliased to `ls -h --color=auto'
ls is /bin/ls
$ type -a echo
echo is a shell builtin
echo is /bin/echo
$ type -a touch
touch is /usr/bin/touch
touch is /bin/touch
Run Code Online (Sandbox Code Playgroud)


ear*_*Lon 7

您可以使用which来确定正在运行的二进制文件。

  • which ssh
  • which Oracle

这些是示例,将返回二进制文件的完整路径。

您也可以使用whereis来定位其他信息,但在这种情况下它可能会让您感到困惑。


Edu*_*ola 6

您也可以使用whereis. 它将显示二进制文件的路径以及一些相关文件,如文档:

whereis program