Skip to content

BASH Shell Aliases

Last updated 2026-10-16 · 4 notes · 4 tags

Tags: bash aliases terminal config

Aliases are short shortcuts for longer commands. Bash reads ~/.bashrc for interactive terminals. You can keep personal settings there, or put them in ~/.bash_aliases and let .bashrc load that file.

Move personal settings into ~/.bash_aliases

On systems that provide /etc/skel/.bashrc (such as many Debian- and Ubuntu-based systems), this workflow saves your current config, starts with the system template, and keeps your custom settings in a separate file.

1. Back up your current config

cp ~/.bashrc ~/.bashrc.bak.$(date +%F)

If ~/.bash_aliases already exists, save a copy before the next step because it will be overwritten. Run this command only when that file exists:

cp ~/.bash_aliases ~/.bash_aliases.bak.$(date +%F)

Note: If either dated backup already exists (for example, because you are repeating these steps the same day), choose a different backup filename so cp does not replace it.

2. Copy the config, then restore the system template

cp ~/.bashrc ~/.bash_aliases
cp /etc/skel/.bashrc ~/.bashrc

Note: The second command replaces ~/.bashrc; the dated backup lets you recover it. If /etc/skel/.bashrc does not exist on your system, stop here and use that system's documented default Bash config instead.

3. Keep only your personal settings

Edit the copied file:

nano ~/.bash_aliases

Remove the copied default startup content and keep your personal aliases, functions, and environment settings. In particular, remove any block that sources ~/.bash_aliases from inside the file itself; the .bashrc should load it, not the other way around.

Note: Do not delete custom export or function lines you still need. The purpose is to separate your personal settings from the standard .bashrc, not to discard them.

The system .bashrc usually loads ~/.bash_aliases when the file exists. If yours does not, add this block to ~/.bashrc:

if [ -f ~/.bash_aliases ]; then
    . ~/.bash_aliases
fi

Add aliases, reload, and verify

Add aliases to ~/.bash_aliases:

# Safer delete (requires trash-cli — see Safe delete above)
alias rm='trash-put'

# Short listing
alias ll='ls -al'

# Move up one or two directories
alias ..='cd ..'
alias ...='cd ../..'

# Colorized search
alias grep='grep --color=auto'

# Jump to projects
alias proj='cd ~/projects'

# Common Git status
alias gs='git status'

The rm alias requires trash-cli; set it up first in Safe delete. You can also add a helper function:

gsync() {
    echo "=== Fetching from GitHub ==="
    git fetch --all --tags
    echo
    echo "=== Local branches ==="
    git branch -vv
    echo
    echo "=== Repository status ==="
    git status
}

Save the file, then open a new terminal or reload the config:

source ~/.bashrc

Verify that your aliases loaded:

alias

Note: If an alias is missing, check that ~/.bashrc sources ~/.bash_aliases and that you edited the file used by Bash.

Environment variables (API keys)

Store secrets in your private shell config or a local .env file that is not committed to Git.

# EXAMPLES ONLY — never commit real keys
# export OPENROUTER_API_KEY="sk-or-v1-your-key-here"
# export GEMINI_API_KEY="your-key-here"

Note: Real keys in a public GitHub repo can be stolen by bots within minutes. Revoke any key that was pushed by mistake.

PATH extras (placeholders)

Tools like pipx often add a line similar to:

export PATH="$PATH:/home/YOUR_USERNAME/.local/bin"

On WSL, a Windows GUI app path might look like:

# Example only — adjust to your Windows username and install path
# alias ollama="/mnt/c/Users/YOUR_WINDOWS_USERNAME/AppData/Local/Programs/Ollama/ollama.exe"

Note: Copy paths from your own machine (which / File Explorer address bar). Do not reuse someone else’s username paths.

Common mistakes

  • Comment lines with # so you remember why an alias exists.
  • After you change ~/.bash_aliases or ~/.bashrc, open a new terminal (or run source ~/.bashrc) to confirm everything still loads.

This project captures ideas, decisions, and lessons I’ve learned while building with AI. It aims to help non-technical users understand and use these tools effectively. I also use AI at times to improve or refine the content.

Readers should use the commands and instructions here with care. The creator accepts no responsibility for system damage, data loss or other consequences resulting from their use.