Is there a way to completely restart Bash and reload .bashrc
and .profile
and the like? I'd like to make sure my changes worked out properly after editing these files.

- 728
- 7
- 13

- 39,676
4 Answers
Have it replace itself with itself.
exec bash -l
Note that this won't affect things such as the cwd or exported variables.

- 45,725
I urgently suggest to log in on a separate window/screen. This way you still have a working session if something goes wrong with your changes to startup files. Also you are sure to have a clean environment.
Reason: I saw too many people locking themselves out of a system because of a simple typo in their .profile (or such).

- 2,717
-
+10, a clean shell where you can change edits is essential. – Sardathrion - against SE abuse Oct 17 '11 at 13:17
-
If your goal is simply to read the modified files again, you don't have to restart it. You can simply source it.
source filename
or
. filename # notice the dot
Note that this won't give you a "clean state" in a sense that it won't unset any set variables or defined functions...

- 20,023
su -l yourOwnUserName
Will open a fresh shell for yourOwnUserName
user with all the settings re-loaded. This is shell-independent, as it refers to system settings, not your specific shell. It also loads some system-wide settings that bash -l
does not (like user groups).

- 39,269
-
1important note: "a fresh shell" here means a shell within your existing shell, so you are only nesting shells, not replacing your original one. The accepted answer does that properly. – underscore_d Sep 24 '15 at 00:40
PATH
is being set as I want or myPS1
, etc. – Naftuli Kay Oct 16 '11 at 22:35exec
and you get a shell that sources the files that you want. Then justexit
when you are done checking. – Arcege Oct 17 '11 at 00:20$PS1
in bash's startup files, yes. – Ignacio Vazquez-Abrams Oct 17 '11 at 03:40-l
does to save time looking it up. – Dan Nissenbaum May 30 '20 at 00:39