익명 15:12

What does hash -r command do?

What does hash -r command do?

I recently switched to linux full time from windows and while I was trying to update my npm package using n, I got the new binaries in /usr/local/bin and previous version was in /usr/bin. So, it was always picking the previous version.

As per recommendation by a fellow user, I used hash -r command and it worked. But, I don't know what it did.

It would be very helpful if someone could explain its internals to me.



Top Answer/Comment:

hash is a built-in command of the bash shell. For a summary of what it does you can type help hash at the shell prompt:

$ 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 as 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.

So, hash remembers program locations, and hash -r forgets them.

상단 광고의 [X] 버튼을 누르면 내용이 보입니다