Where should I define shell aliases? That is, what is the best practice (and why)?
I can think of the following options:
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It only takes a minute to sign up.Sign up to join this community
The options you mention refer to different shells. When a user starts a shell program, the relevant
rc file in the user's home directory is read. If you are using bash (as you will be when you open a terminal in Ubuntu, unless you have installed and selected a different shell as default for your user), then you should put your aliases either in
.bashrc, or if you prefer (for example so you can more easily see and edit all your aliases), in a dedicated
.bash_aliases file. This file does not exist by default, but if it is created, it will be sourced when bash is started by the default
$ grep -n '^[^#]*bash_alias' /etc/skel/.bashrc 104:if [ -f ~/.bash_aliases ]; then 105: . ~/.bash_aliases
If you are using another shell, then use the appropriate
rc for that shell.