Intermediate · 7 min · practise every command in the built-in terminal

.bashrc and .profile

These files run automatically when you open a shell.

Files and when they run

FileWhen it runs
~/.bashrcEvery new interactive bash shell
~/.bash_profileLogin shells only
~/.profileLogin shells (any shell)
~/.bash_aliasesUsually sourced from .bashrc
/etc/profileSystem-wide, all users
/etc/bash.bashrcSystem-wide bashrc

Editing .bashrc

nano ~/.bashrc

Common .bashrc contents

# Aliases
alias ll='ls -la'
alias grep='grep --color=auto'

# Custom PATH
export PATH="$HOME/scripts:$PATH"

# Editor
export EDITOR=nano

# Custom prompt
export PS1='\[\033[1;32m\]\u@\h\[\033[0m\]:\[\033[1;34m\]\w\[\033[0m\]\$ '

# History settings
export HISTSIZE=10000
export HISTFILESIZE=20000
export HISTCONTROL=ignoredups:erasedups

# Functions
function mkcd() { mkdir -p "$1" && cd "$1"; }

Reload without logging out

source ~/.bashrc
. ~/.bashrc           # Same thing, shorthand

Practice tasks

  1. View the contents of your .bashrc file
  2. Add an alias to .bashrc and reload it
  3. Add a custom EDITOR setting to .bashrc
  4. Reload .bashrc using the dot shorthand instead of source

Commands in this lesson

Shell & Environment