~/.bash_profile
and ~/.bashrc
are shell scripts that contain shell commands. These files are executed in a user's context when a new shell opens or when a user logs in so that their environment is set correctly. As we mentioned~/.bash_profile
is executed for login shells and ~/.bashrc
is executed for interactive non-login shells.~/.bash_profile
script is executed before the initial command prompt is returned to the user. After that, every time a new shell is opened, the ~/.bashrc
script is executed. Most of the time PATH and env vars go into the in ~/.bash_profile and aliases go into the ~/.bashrc.
alias
command and remove them with the unalias
command./home/user/.bashrc
:Another common use of aliases is for the root user. Thecp
,rm
, andmv
commands are usually aliased to include the-i
parameter, to help prevent accidental destruction of files.
source
(or .
) command. $1
returns the first argumentunset
command inorder to unset our defined function.