簡體   English   中英

在 linux 中,如何獲取我正在使用的命令的完整路徑?

[英]In linux, how to get the full path of a command I am using?

如何獲取我正在使用的命令的完整路徑?

例如,我已將 jdk 安裝到/opt/Oracle/jdk1.7.0_25中,我的PATH如下所示:

/opt/Oracle/jdk1.7.0_25/bin/:/usr/lib/x86_64-linux-gnu/qt4/bin:/home/unimous/bin:/usr/lib/lightdm/lightdm:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games. 

我想從java /opt/Oracle/jdk1.7.0_25/bin/java

which java

應該給你完整的路徑。

這也適用於Linux中的任何其他命令,只需使用which command_name

這取決於你的發行版,在debian和debian發行版中你有更新替代品

而對於你的java,你做的例如:

update-alternatives --install“/ usr / bin / java”“java”“/ opt / Oracle / jdk1.7.0_25 / bin / java”3

Help section on update-alternatives 

update-alternatives: --install needs <link> <name> <path> <priority>

Usage: update-alternatives [<option> ...] <command>

Commands:
  --install <link> <name> <path> <priority>
    [--slave <link> <name> <path>] ...
                           add a group of alternatives to the system.
  --remove <name> <path>   remove <path> from the <name> group alternative.
  --remove-all <name>      remove <name> group from the alternatives system.
  --auto <name>            switch the master link <name> to automatic mode.
  --display <name>         display information about the <name> group.
  --query <name>           machine parseable version of --display <name>.
  --list <name>            display all targets of the <name> group.
  --get-selections         list master alternative names and their status.
  --set-selections         read alternative status from standard input.
  --config <name>          show alternatives for the <name> group and ask the
                           user to select which one to use.
  --set <name> <path>      set <path> as alternative for <name>.
  --all                    call --config on all alternatives.

<link> is the symlink pointing to /etc/alternatives/<name>.
  (e.g. /usr/bin/pager)
<name> is the master name for this link group.
  (e.g. pager)
<path> is the location of one of the alternative target files.
  (e.g. /usr/bin/less)
<priority> is an integer; options with higher numbers have higher priority in
  automatic mode.

Options:
  --altdir <directory>     change the alternatives directory.
  --admindir <directory>   change the administrative directory.
  --log <file>             change the log file.
  --force                  allow replacing files with alternative links.
  --skip-auto              skip prompt for alternatives correctly configured
                           in automatic mode (relevant for --config only)
  --verbose                verbose operation, more output.
  --quiet                  quiet operation, minimal output.
  --help                   show this help message.
  --version                show the version.

如果你在bash:

type java

type是內置的,通常是一個單獨的可執行文件:

$ type type
type is a shell builtin
$ type which
which is hashed (/usr/bin/which)

而不是使用which ,使用type命令。 which命令僅提供找到第一個命令的路徑。 -atype命令給出所有路徑,包括別名:

type -a java

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM