Contents

Introduction

When a Unix shell is initialized, it reads and executes commands from a set of configuration files. These files are used to set up the shell environment, including environment variables, aliases, and functions. The specific files that are executed depend on the type of shell being used and whether the shell has registered a login operation.

The Home Directory

Profile files and RC files should be located in the user’s home directory. To see the location of your home directory, execute one of the following commands in your preferred Unix shell command line interface (CLI).

echo $HOME
cd ~
pwd


If a profile file or RC file does not exist, you can create it using the touch command. For example, to create a .bash_profile file, execute the following command in your preferred Unix shell CLI.

touch ~/.bash_profile


Additional information about Unix shell commands can be found in the Unix Commands guide.

Shell Profile Files

Shell profile files are executed when a user logs in to the shell. On a personal computer, opening a new shell window will typically register as a login operation.

In Bash shell, the profile file is typically called .bash_profile.

In Z shell, the profile file is typically called .zprofile.

Shell RC Files

RC files are executed when a new shell is started or initialized. This includes opening a new shell window or executing a shell script (e.g. bash or zsh).

In Bash shell, the RC file is typically called .bashrc.

In Z shell, the RC file is typically called .zshrc.

Editing Profile and RC Files

Editing on macOS

You can edit profile and RC files on macOS using the TextEdit application. You can open files in TextEdit from the command line using the open command. For example, to open the .bashrc file, execute the following command in your preferred Unix shell CLI.

open ~/.bashrc

Editing on Windows

You can edit profile and RC files on Windows using the Notepad application. You can open files in Notepad from the command line using the notepad command. For example, to open the .bashrc file, execute the following command in your preferred Unix shell CLI.

notepad ~/.bashrc

Editing from the Command Line

You can edit profile and RC files directly from the command line using a wide range of command line text editors, including nano, vi, and vim. Additional information about vi can be found in the vi guide.

For additional information about command line editors, the following resources may be helpful:

Wikipedia - GNU nano

Wikipedia - Vim (text editor)

Resources and References

For additional information about Unix shell configuration, the following resources may be helpful:

Red Hat Blog - How to customize Linux user environments

Red Hat Blog - Linux environment variable tips and tricks

GeeksforGeeks - bashrc vs. bash_profile: What Is the Difference?

Tutorials Point - Shell Initialization Files and User Profiles in Linux

Tutorials Point - Difference Between .bashrc, .bash-profile, and .profile

Tutorials Point - Unix / Linux - Environment


Back to top.