Your shell's startup file
Every variable and setting made at the prompt dies when the terminal closes. To make things permanent, bash reads a startup file each time a new interactive shell opens: ~/.bashrc, or ~/.bash_profile on some systems.
Notice the name. It begins with a dot, so it is one of the hidden dotfiles that ls -a revealed back in lesson 2-3. Anything written in it, whether variables, PATH additions, or aliases, is applied again in every future terminal.
After editing it, either open a new terminal or reload it in place:
source ~/.bashrcThis is the point where the terminal stops being a generic tool and becomes your tool. Developers grow fond of their dotfiles, and many keep them in version control so a new machine feels like home within minutes.
Aliases: your own shorthand
An alias gives a long command a short name:
alias ll='ls -l' alias gs='git status'
Type ll and the shell silently substitutes ls -l before running. Aliases live in .bashrc so they exist in every terminal.
One technicality for the script below: scripts don't expand aliases by default (they're an interactive-shell convenience), so the demo flips that on with shopt -s expand_aliases. In your real terminal, plain alias in .bashrc just works.
Defining an alias and calling it
An alias is defined once and then used as though it were a real command.
shopt -s expand_aliases alias shout='echo LOUD AND CLEAR' shout
Output
LOUD AND CLEAR
The single quotes keep echo LOUD AND CLEAR together as one value, so the whole command becomes the alias rather than just the first word. When shout is then typed on its own, the shell substitutes that text and runs it.
For alias ll='ls -l' to work in every terminal you ever open, it belongs in ~/.bashrc.
That file runs automatically whenever a new interactive shell starts, so any definition inside it is always present. An alias typed directly at the prompt works too, but only until that terminal closes, since nothing records it anywhere.
The alias syntax is alias name='command', and once defined the name can be used on its own line like any other command.
shopt -s expand_aliases alias greet='echo hello from my alias' greet
Output
hello from my aliasEverything inside the single quotes becomes the replacement text, which is why the multi-word echo hello from my alias survives intact. In a real terminal the shopt line is unnecessary, since interactive shells expand aliases by default.
To activate a newly added alias in the current terminal without opening a new one, run source ~/.bashrc.
source re-executes the startup file inside the shell you are already in, so new aliases and variables take effect immediately. The single-dot form, . ~/.bashrc, is exactly the same command spelled differently. What makes this work is that the startup file is nothing more special than a file of shell commands, and source reads them into the running shell rather than starting a child.