50

When I make some changes to the shell/bash behavior, such as setting up an alias, is there a quick command to reinitialize the terminal window instead of closing and opening a new window?

53

If you mean reloading your .bashrc configuration then:

source ~/.bashrc

For less typing, you can replace source with a dot: . ~/.bashrc

  • 2
    Here is a question, how does this behave differently than source ~/.bashrc ? – crasic Jan 3 '11 at 5:49
  • It doesn't. Looking at the bash man page you will see that the commands are listed as equivalent. – Carsten Thiel Jan 3 '11 at 13:44
  • 2
    source is a specific to bash. . is more standard. Both work the same in bash. – Michael Terry Jan 27 '11 at 18:36
  • 1
    This just reloads your PATH and some environment variables. It doesn't "reset" anything. @NES's answer is the correct one. – Cerin Jun 12 '17 at 1:46
  • 2
    This doesn't reset anything, if you had updates to your PATH you'll now have your old updates and new updates. – Constantin Aug 8 '18 at 15:33
39

Some Addition i found in the manpage from the reset/tset command

tset reset terminal intialization

command: reset

Tset initializes terminals. Tset first determines the type of terminal that you are using. This determination is done as follows, using the first terminal type found.

an advantage seems to be, that it's independent from the used shell. also works with fish here.

So to reinitialize any terminal just do-

$ tset

OR

$ reset
  • Unfortunately this is also wrong. It does not reset existing environment variables. – isarandi Mar 28 at 7:25
9

An additional option to the exec bash is that if you changed your .profile (or .bash_profile), you can do

$ exec bash --login

That will read your profile again as well. It wouldn't hurt to add the -i option as well to explicitly tell bash that this is an interactive shell, but it can normally figure that out for itself.

  • for me it works without exec too – Armen Sanoyan Dec 10 '17 at 15:52
  • Unfortunately wrong as well. Already set environment variables are still there and aren't reset. – isarandi Mar 28 at 7:26
6

You have to replace the running application/shell with a new instance. E.g. if you are using bash as your preferred shell type the following line in your command line ($ is the placeholder for the beginning of your command line):

> $ exec bash

The running application/shell is replaced by new instance of bash like starting from scratch. All your previous modification are gone.

Remark: Do not forget that your terminal application may be reprogrammed. You have to reset your terminal application manually.

  • 2
    What do you mean by "reprogrammed"? – Eliah Kagan Aug 11 '12 at 3:53
0

your shell is an executable you can call. So if you're using bash you can call bash and if you're using something else like zsh you can just enter zsh

0

Use exec sudo --login --user $USER.

If you also want the previously entered commands to disapper (full reset of the terminal), combine it with reset as reset; exec sudo --login --user $USER

There are many answers around the web but most don't actually work. Easy way to test is to set export SOMEVAR=42 then execute the supposedly resetting command and do echo $SOMEVAR. If it's 42, the environment was not reset.

There is also exec -c bash -l or exec env -i bash -l, but these are broken, somehow the $HOME variable is not set after this.

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.