Quick Links
Summary
The shell is so important to Linux, it has its own startup process. Discover how to configure the shell on startup, how to run commands automatically, and what you can do with all this power.
What .bashrc Does and Why
The .bashrc file is typicallyhidden in your home directory. It is a “run control” file that originated with Bash (Bourne Again Shell), the most popular and widely used Linux shell. Linux uses run control files to script and configure commands when they start, so .bashrc is a startup script for the shell itself.
.bashrc should do whatever is necessary to set up your environment for an interactive shell session. This includes setting environment variables, defining functions, and running utility programs. Once you know how it works, you’ll find various uses to customize and streamline your shell experience.

How .bashrc Works
First of all, know that Bash is not the only shell. On macOS, you’re probably usingzsh, a powerful alternative. Most Linux distros use Bash, but there’s no guarantee yours does. To find out which shell you’re running, open a terminal window and run this command:
The output should be something like “bash” or “-zsh”, identifying your specific shell.

Next, you may not already have a .bashrc (or equivalent) file, depending on your distro. Try running the following:
This command will show you all hidden files in your home directory that end in “rc”:

If you don’t see .bashrc, you may create an empty file with that name. You can also copy a template from /etc/skel/.bashrc if you have it:
The startup process can be quite complicated, so you might want to read aboutthe differences between .bashrc and .profilebefore you begin, or if you run into any problems.

In the general case, though, you’re able to expect the .bashrc file to run when you open a new terminal, including a new window or tab.
6 Things You Can Do With .bashrc
Because .bashrc is, itself, a Bash script, you can use it for many different purposes. The limit really is your imagination, but the following uses are common.
Run neofetch and Alternatives
Since .bashrc runs when you open a new terminal, it’s a nice place to inject a bit of personality into your terminal. Anything that can act as a welcome message is a nice addition, and neofetch is one of the nicest:
The program shows some colorful ASCII art alongside information about your machine. Apart from being a nice way to begin your terminal session, it’s useful for recognizing that you’re on the machine you think you are—especially useful if you often ssh out to remote machines.

Neofetch is now discontinued, so although you can still use it, you might want toseek out a newer alternativethat is being actively developed. Good alternatives includeFastfetchandscreenFetch, which are drop-in replacements written in C and Bash script respectively, andonefetchwhich displays details of a git project you may be working on.
Whichever tool you choose, it’s easy to get it running via .bashrc. First, verify the plain command works, e.g.

Then simply add the same command to .bashrc:
Customize Your Prompt
A more low-key way of customizing your terminal environment is by setting your prompt. This is the bit of text that Linux prints at the beginning of each line in your terminal, prompting you to type something.
The default is fairly useful, butyou can customize the promptto include almost anything. Using the built-in variables, you can include the hostname, user, date, and more. I like this setup:

This adds an extra line which makes it clearer to spot where output from a previous command ends. It also removes the username and host which I don’t really use.
Your default .bashrc probably includes some PS1 configuration already. You can add yours afterward if you want, as I have here:

Set Aliases to Make Commands Easier
Aliasing is another powerful customization that can make your terminal more pleasant to use. Bysetting an alias for a command, you can give it a more memorable name or one that’s easier to type. You can also use aliases to make it easier to use common combinations of options.
My .bashrc sets several aliases for the ls command:
As with all environmental setup, aliases can be defined in several places, so it’s worth checking the current aliases before you start, using the alias command on its own:
Create Shell Functions for Common Tasks
Even more powerful than aliases, shell functions let you write your own mini-commands. If you define a shell function inside .bashrc, you can run it by typing its name, just like any other command.
Here’s a simple example that you might find saves you some time. It calls mkdir with the useful -p option which creates a full path, including new intermediate directories. It then changes to that new directory:

The real win here is that you can now use “mkd” as a substitute for “mkdir”:
Define Environment Variables to Control Commands
Many commands use either global or specificenvironment variablesto alter their behavior. Common widely-recognized env vars include:
But command-specific variables can be just as useful. Take the pager, less, as an example. It supports a LESS variable which you can use to pass default options. For example:

Add this to your .bashrc and less will always act nicely, even with files shorter than one screen page. Many commands support similar environment variables that you can set in .bashrc to change their default behavior. Look for a section headed “Environment” or “Environment Variables” in each command’s man page.
Modularize Your Environment by Sourcing Other Files
Once you get into shell customization, your .bashrc file can grow until it’s quite unwieldy. Never mind: this is the perfect opportunity to learn about, and practice, modularization.
Splitting one large file into several smaller ones can make the whole easier to manage, and can enable sharing for other purposes. A well-defined structure can make it easier for others to read, even if future-you is one of those others.
The skeleton bashrc that came with my distro explains how to do this, with clear comments:
In this case, a file at ~/.bash_aliases will be sourced (via the . command) if it exists. The effect will be exactly as if those aliases were directly included in your .bashrc.