Unix / Linux: Initialize Dot Files Without Restarting The Current Shell Session

Posted on in Categories , , , , , last updated January 11, 2015

I‘m a new Linux, OS X or Unix-like system users. I’m using bash shell. I made changes to my $HOME/.profile ($HOME/.bash_profile) file. How can I restart my session without doing logout and login again?

You can always initialize your shell startup files without restarting a Unix or Linux based session. The command and input file name depends upon your shell you are using. You can use the following command to find out your shell name:

echo $SHELL

Sample outputs:

/bin/csh

Restart a Unix/Linux session based on ksh or bash shell

The syntax is:

. $HOME/.profile  
. $HOME/.bash_profile  
 
## or Use source command ##
source $HOME/.profile  
source $HOME/.bash_profile

The source or . is a shell builtin commands to read and execute commands from given FILENAM. If you have created a $HOME/.bashrc file, type:

. $HOME/.bashrc
 
## or 
 
source $HOME/.bashrc

Restart a Unix/Linux session based on csh or tcsh shell

The syntax is as follows for csh/tcsh based shell:

source .cshrc
source .login

For more info see your shell man pages – bash(1),tcsh(1),ksh(1) or type the following command:

help source
help .

Posted by: Vivek Gite

The author is the creator of nixCraft and a seasoned sysadmin and a trainer for the Linux operating system/Unix shell scripting. He has worked with global clients and in various industries, including IT, education, defense and space research, and the nonprofit sector. Follow him on Twitter, Facebook, Google+.

5 comment

  1. $SHELL does not necessarily contain the current shell; it contains the default shell (and it should be ‘echo “$SHELL” ‘, not ‘echo $SHELL’).

    You would not want to “source $HOME/.bash_profile” in ksh.

    “help source” is bash syntax not ksh (that would be “source –help”).

  2. With bash I usually do “exec bash -il”. I get similar commands exist for other shells.

Comments are closed.