It is largely up to you and how you use your computer. bash_aliases
is not a standard file, this is something Ubuntu adds to the system. If you look at Ubuntu's default .bashrc
(/etc/skel/.bashrc
), you will see:
if [ -f ~/.bash_aliases ]; then
. ~/.bash_aliases
fi
Ubuntu sets itself up to source (read) that file (the .
means read the file into the current shell) if it exists. So if you are planning to migrate your setup somewhere else, don't use bash_aliases
at all.
If you only care about Ubuntu, then using bash_aliases
or bashrc
is the same thing. They will both be read at the same time since one sources the other, so the choice of which one to use is up to you.
That said, the .bashrc
file is absolutely intended to be edited by the user and not to be administered by the OS, so you should feel free to edit it. Traditionally, you would put aliases and functions in ~/.profile
, however, since .bashrc
is read every time you start a new interactive non-login shell, while .profile
is only read by interactive login shells. In practice, on a modern graphical system, that means that .bashrc
(and .bash_aliases
on Ubuntu) is read every time you open a new terminal, while .profile
will be read only when you log in. So people would try to keep .bashrc
streamlined so it wouldn't take too long to be read each time. However, on modern systems, it really doesn't make any noticeable difference. Our machines are fast enough to read larger files with no issue at all.
Another consideration is that .profile
and .bashrc
are read by different kinds of shell, login and non-login respectively as mentioned above. See my answers here and here for more details on this. The point is that on traditional systems, when running a non-login shell, .profile
is not read. however, Ubuntu like its parent Debian, has a special line in its .profile
that sources .bashrc
:
$ grep -A1 bashrc /etc/skel/.profile
# include .bashrc if it exists
if [ -f "$HOME/.bashrc" ]; then
. "$HOME/.bashrc"
fi
All this means that you can add functions to your .bashrc
or .bash_aliases
files as you like, and they will still be available to login shells. You might want to use .profile
instead, but feel free to use .bashrc
. That's what it's for: for the user to define extra stuff for their shell.
Some useful references:
~/.bashrc
is what I would normally use for user defined functions. – Raffa Feb 23 '24 at 12:41what
on the command line to run a script. – Wastrel Feb 24 '24 at 15:16