更改软链接后如何更新“命令缓存”?

mab*_*enk 4 shell path command

我已经用ln -f -s. 当我查看带有 的链接时ls -l,我看到它们指向正确的目标。

但是,当我尝试运行该命令时,它仍然尝试使用“旧”目标。

是否有 Linux 命令刷新“命令缓存”以告诉系统使用新创建的软链接?

例如:

OPEN_MPI_PATH=/usr/lib64/mpi/gcc/openmpi
ln -f -s ${OPEN_MPI_PATH}/bin/mpirun  /usr/bin/mpirun
ls -l /usr/bin/mpirun
$ /usr/bin/mpirun -> /usr/lib64/mpi/gcc/openmpi/bin/mpirun
Run Code Online (Sandbox Code Playgroud)

执行mpirun -np 4 hello_world结果调用英特尔 MPI,这是一个“旧”目标。

phe*_*mer 7

我将假设您正在谈论更改在 中找到的内容$PATH,并且您所在的 shell 仍在启动原始程序。

如果是这样,你要找的是 hash -r

$ help hash
hash: hash [-lr] [-p pathname] [-dt] [name ...]
    Remember or display program locations.

    Determine and remember the full pathname of each command NAME.  If
    no arguments are given, information about remembered commands is displayed.

    Options:
      -d            forget the remembered location of each NAME
      -l            display in a format that may be reused as input
      -p pathname   use PATHNAME is the full pathname of NAME
      -r            forget all remembered locations
      -t            print the remembered location of each NAME, preceding
                    each location with the corresponding NAME if multiple
                    NAMEs are given
    Arguments:
      NAME          Each NAME is searched for in $PATH and added to the list
                    of remembered commands.

    Exit Status:
    Returns success unless NAME is not found or an invalid option is given.
Run Code Online (Sandbox Code Playgroud)

  • 那么缓存不是你的问题。你的 `$PATH` 可能在 `/usr/bin` 之前还有别的东西。 (2认同)