4

I have changed multiple soft links on my system with ln -f -s. When I view the link with ls -l, I see they point to the right target.

However, when I try to run the command, it still tries to use the 'old' target.

Is there a Linux command to refresh the 'command cache' to tell the system to use the newly-created soft links?

For example:

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

Execution of mpirun -np 4 hello_world results in a call to Intel MPI, which was an 'old' target.

1
  • You should provide an example of what you're changing, and an example of the behavior which is incorrect. As it is it's kind of difficult to tell what you're referring to. Commented Jul 8, 2014 at 15:53

1 Answer 1

7

I'm going to assume you're talking about changing something found in $PATH, and that the shell you are in is still launching the original program.

If so, what you're looking for is 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.
4
  • This doesn't help. When I run hash -r and follow it up by hash. I get a result of hash table is empty. But running mpirun still results in the call to Intel MPI. Commented Jul 8, 2014 at 16:11
  • 2
    Then the cache isn't your issue. Your $PATH likely has something else before /usr/bin. Commented Jul 8, 2014 at 16:13
  • Yes, you are right. The problem was in the $PATH. Intel gets their products as first in the $PATH. But how do I downgrade them? Is there a more elegant way either then reinforcing /usr/bin/ with export PATH=/usr/bin/:$PATH? Commented Jul 8, 2014 at 16:31
  • This is why most people set PATH so that /usr/local/bin is first. System packages don't install to /usr/local, so you put your custom stuff there, and make sure it's first in the $PATH. That is the proper way of solving it. Commented Jul 8, 2014 at 22:57

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.