【问题标题】:In linux, how to get the full path of a command I am using?在 linux 中,如何获取我正在使用的命令的完整路径?
【发布时间】:2013-09-07 12:10:19
【问题描述】:

如何获取我正在使用的命令的完整路径?

比如我把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

【问题讨论】:

    标签: linux path


    【解决方案1】:
    which java
    

    应该给你完整的路径。

    这也适用于 Linux 中的任何其他命令,只需使用 which command_name

    【讨论】:

      【解决方案2】:

      这取决于你的发行版,在 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.
      

      【讨论】:

        【解决方案3】:

        如果你在 bash 中:

        type java
        

        type 是内置的,通常是单独的可执行文件:

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

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2018-12-02
          • 1970-01-01
          • 2015-02-05
          • 2015-04-02
          • 1970-01-01
          • 2011-10-27
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多