When I type man hash it shows me man builtin.

I'm trying to understand this line:

hash -r 2>/dev/null || true

What hash -r does and what it returns.


export PATH="$PWD/bin:$PATH"
hash -r 2>/dev/null || true



hash is a shell builtin.

If you are using bash, check:

help hash

For your convenience, here it is:

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.

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

For other shells, check the usual place for builtins. For example, for zsh, check:

man zshbuiltins

What hash -r does and what it returns.

hash -r removes all remembered locations from the hash table and it returns success.


hash is a standardized shell builtin and hash -r resets the current path hash that is used to locate comands in PATH.

Calling hash -r after setting PATH is however not needed as changing PATH automatically resets the current command hashing. This is true for the Bourne Shell and for ksh and I would expect other shells to behave the same way.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.