Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I had a function inside .zshrc that I removed.

Now, when I try to source it, it indeed sources it, but doesn't remove the function that once was inside .zshrc from memory.

Is there a way to remove the function (now I believe in memory, in zsh namespace or something like that) without restarting my machine?

share|improve this question
You don't need to restart your machine, obviously. exec zsh will get you a fresh shell in the same terminal, directory, environment, etc. – Gilles Mar 8 '11 at 18:55
up vote 4 down vote accepted

In zsh, you can remove a function with unhash -f functionname or unfunction functionname.

That doesn't automatically clear functions you've removed from a given startup file, though, because of course the shell doesn't remember where it got it from in the first place and attribute any special meaning to re-sourcing the same file. So you'll have to know what you want to forget.

Since you mention .bashrc in the subject: the bash equivalent is unset -f functioname

share|improve this answer
If a function is binded to a key (bindkey command), is it possible to remove it as well? – Somebody still uses you MS-DOS Mar 7 '11 at 21:34
@Somebody still uses you MS-DOS — if you remove the function without removing the key binding, you'll get No such shell function `function' when you press the key. But perhaps what you want to do is start your key definitions in your dotfile with bindkey -d, to reset them to their default state each time before setting up custom things. – mattdm Mar 7 '11 at 21:54

unhash -mf "*" can be used to clear all functions.
Since it will wipe out the standard zsh goodness functions you will need to reload /etc/zsh/zshrc.

I have the following at the beginning of my .zshrc:

# Clear all functions and aliases
unhash -mf "*"
unhash -ma "*"
. /etc/zsh/zshrc  # reload standard functions and aliases
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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