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

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

我已经使用 更改了系统上的多个软链接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

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

答案1

我假设您正在谈论更改在 中找到的某些内容$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.

相关内容