Find your shell's configuration file
Written: 17 Dec 2021 | Last updated: 11th Dec 2023
Most (all?) Bourne Shell based shells (*sh shells) use a configuration file which is run every time a new terminal is opened. Generally these can be recognised because they end end with a rc
which is an acronym for "run commands".
These configuration files can be used for local (i.e. for one user) CLI changes such as adding custom commands or variables.
As a general rule they (tend to) be found at ~/.SHELLrc
where SHELL
is the name of your shell.
If the configuration file appears to be missing:
- Check that hidden files are visible to you. The
.
at the start of the file name indicates that it is a hidden file.
In your terminal you can usels -a
to see all files in a directory. - If you still can't find it create the file in its expected location.
- Bash (Bourne-Again shell)
- Located at:
~/.bashrc
. - Csh (C shell)
- Located at:
~/.cshrc
. - Ksh (Korn shell)
- Located at:
~/.kshrc
. - Zsh (Z shell)
- Located at:
~/.zshrc
.
On macOS the configuration file does not exist by default so you will need to create it in that location.
Create shell rc file
Create your file at the correct location.
Add #!bin/sh
to the first line. Alternatively, you could just put a single colon (:
) but the first method is preferable.
If this returns errors when you run the file you can check the location of sh
using which sh
and place that after the shebang (#!
) instead.