Article Information

Category: Development

Published: 7 March, 2026

Author: Chris de Gruijter

Reading Time: 7 min

Tags

bashterminalproductivitylinuxdeveloper tools
Terminal command line interface on a developer screen

Working Faster with Bash Aliases: A Developer's Productivity Setup

Published: 7 March, 2026

Every developer has a set of commands they type dozens of times a day. cd ~/Projects/some/deeply/nested/path. npm run dev. git status. git log --oneline -20. These are fast to type individually, but the cumulative friction across a full workday adds up — and more importantly, they interrupt your flow.

Bash aliases eliminate that friction entirely. Instead of typing a full path or command chain, you type one word and it just works. This post covers how to set up a structured alias system in your .bashrc that scales across multiple projects without becoming a mess you can't maintain.

The Basics: What Bash Aliases Are

A bash alias is a shortcut that maps a short command to a longer one. They live in your ~/.bashrc (or ~/.bash_aliases if you prefer to keep them separate) and are loaded every time you open a new terminal session.

# Basic alias syntax
alias shortname='command to run'

# Examples
alias ll='ls -alF'
alias gs='git status'
alias glog='git log --oneline -20'
alias ..='cd ..'
alias ...='cd ../..'

After adding aliases to your .bashrc, reload it without restarting your terminal:

source ~/.bashrc

The Key Pattern: Path Exports First

The single most important habit for a scalable alias setup is defining project paths as exported variables first, then referencing those variables in aliases. This way, if a project moves, you change one line and every alias that references it updates automatically.

# ─── Define paths ONCE at the top ───────────────────────────
export MYAPP="$HOME/Projects/my-app"
export MYAPP_API="$HOME/Projects/my-app/apps/api"
export MYAPP_WEB="$HOME/Projects/my-app/apps/web"

# ─── All aliases reference the variables ─────────────────────
alias myapp='cd $MYAPP'
alias myapp-api='cd $MYAPP_API'
alias myapp-web='cd $MYAPP_WEB'

# ─── Dev server aliases ────────────────────────────────────────
alias myapp-dev='cd $MYAPP && pnpm dev'
alias myapp-web-dev='cd $MYAPP_WEB && npm run dev'

If the project moves from ~/Projects/my-app to ~/Work/my-app, you update one export line. Every alias that references $MYAPP is automatically corrected.

Structuring Aliases by Project

Once you have more than a handful of projects, organize your aliases with clear section headers. This makes the file scannable and easy to maintain:

# ╔══════════════════════════════════════════════════╗
# ║  MY APP PROJECT                                  ║
# ╚══════════════════════════════════════════════════╝

# Navigation
alias myapp='cd $MYAPP'
alias myapp-web='cd $MYAPP_WEB'
alias myapp-api='cd $MYAPP_API'

# Dev servers
alias myapp-dev='cd $MYAPP && pnpm dev'
alias myapp-web-dev='cd $MYAPP_WEB && npm run dev'

# Build
alias myapp-build='cd $MYAPP && pnpm build'

# Git
alias myapp-status='cd $MYAPP && git status'
alias myapp-push='cd $MYAPP && git push'
alias myapp-pull='cd $MYAPP && git pull'
alias myapp-log='cd $MYAPP && git log --oneline -20'

The naming convention matters. Using a consistent prefix per project (e.g., myapp-) means you can type the prefix and hit Tab to see all available aliases for that project. It turns Tab completion into a self-documenting system.

Multi-Step Aliases with &&

Aliases can chain multiple commands with &&. This is particularly useful for "open and start" workflows:

# Navigate to project, open editor, start dev server
alias myapp-start='cd $MYAPP && code . && pnpm dev'

# Full project rebuild from scratch
alias myapp-fresh='cd $MYAPP && rm -rf node_modules && pnpm install && pnpm build'

# Deploy flow
alias myapp-deploy='cd $MYAPP && git pull && pnpm build && pnpm deploy'

Be careful with chained aliases for destructive operations (like rm -rf). Add an echo confirmation or break them into steps you run manually for anything irreversible.

System Backup Aliases

One of the most practical uses of bash aliases is automating system backups. Rather than remembering complex copy commands, you define them once and run them with a single word:

BACKUP_DIR="$HOME/backups/system"

# Back up your shell config
alias backupbashrc='cp ~/.bashrc "$BACKUP_DIR/bashrc-backup" && echo "✓ .bashrc backed up"'

# Back up git config
alias backupgit='cp ~/.gitconfig "$BACKUP_DIR/gitconfig-backup" && echo "✓ .gitconfig backed up"'

# Export all installed apt packages
alias backuppkgs='dpkg --get-selections | grep -v deinstall | awk "{print \$1}" > "$BACKUP_DIR/packages-apt.txt" && echo "✓ $(wc -l < "$BACKUP_DIR/packages-apt.txt") packages exported"'

# Run all backups at once
alias backupall='backupbashrc && backupgit && backuppkgs && echo "✅ Full backup complete"'

Useful General-Purpose Aliases

Beyond project-specific aliases, there are a handful of general-purpose shortcuts worth having in every setup:

# ─── Navigation ──────────────────────────────────────
alias ..='cd ..'
alias ...='cd ../..'
alias ~='cd ~'

# ─── File listing ────────────────────────────────────
alias ll='ls -alF'          # Long list with hidden files
alias la='ls -A'            # All files except . and ..
alias lt='ls -alFt'         # Sorted by modification time

# ─── Git shortcuts ───────────────────────────────────
alias gs='git status'
alias ga='git add -A'
alias gc='git commit -m'    # Usage: gc "message"
alias gp='git push'
alias gl='git log --oneline -20'
alias gd='git diff'

# ─── npm/pnpm shortcuts ──────────────────────────────
alias ni='npm install'
alias nid='npm install --save-dev'
alias nrd='npm run dev'
alias nrb='npm run build'
alias pi='pnpm install'
alias prd='pnpm dev'
alias prb='pnpm build'

# ─── System ──────────────────────────────────────────
alias reload='source ~/.bashrc && echo "✓ .bashrc reloaded"'
alias bashrc='code ~/.bashrc'   # Open .bashrc in editor

Making Your Setup Portable

The best alias setup is one you can restore in minutes on a new machine. Keep your .bashrc in version control or back it up alongside your dotfiles. A simple backup alias makes this automatic:

# Run this after every session where you added new aliases
alias save-aliases='cp ~/.bashrc ~/Projects/Personal/dotfiles/bashrc-backup && echo "✓ Aliases saved to dotfiles repo"'

On a new machine, restoring is as simple as copying your backup over:

cp ~/Projects/Personal/dotfiles/bashrc-backup ~/.bashrc
source ~/.bashrc

A Note on Alias vs Function

Aliases work great for fixed commands, but they can't accept arguments. When you need a command that takes input, define a bash function instead:

# This won't work — aliases can't take arguments
# alias mkcd='mkdir $1 && cd $1'  ← WRONG

# Use a function instead
mkcd() {
  mkdir -p "$1" && cd "$1" && echo "✓ Created and entered $1"
}

# Another useful function: find and kill a process by port
killport() {
  lsof -ti tcp:"$1" | xargs kill -9 && echo "✓ Killed process on port $1"
}

# Quick git commit with auto-add
gacp() {
  git add -A && git commit -m "$1" && git push
}

Mix aliases (for fixed shortcuts) and functions (for parameterized commands) in the same .bashrc — they work seamlessly together.

Frequently Asked Questions

What's the difference between putting aliases in .bashrc vs .bash_aliases?

Functionally identical — .bashrc typically sources .bash_aliases if it exists. The advantage of .bash_aliases is separation: your shell config stays clean and you have one dedicated file for aliases. The disadvantage is one more file to manage. For most developers, keeping everything in .bashrc is simpler.

Do bash aliases work in scripts?

No — bash aliases are only available in interactive shells. Scripts run in non-interactive mode and don't load .bashrc. In scripts, define functions or use the full commands. You can force alias expansion in a script with "shopt -s expand_aliases" at the top, but this is generally considered bad practice.

How do I see all my currently active aliases?

Run "alias" with no arguments to list every currently loaded alias. To search for a specific one, pipe through grep: alias | grep git

My aliases aren't working after I add them — what's wrong?

You need to reload your .bashrc after editing it. Run "source ~/.bashrc" (or the alias "reload" if you've defined it). Changes only apply to new terminal sessions automatically — existing sessions need a manual reload.