A quick guide to automating repetitive terminal commands with bash aliases
We've all been there—typing the same git commands, npm scripts, or directory navigations 50 times a day. Your fingers hurt, your productivity suffers, and you're wasting mental energy on muscle memory instead of actual coding.
Here's the fix: bash aliases. Two minutes to set up, infinite time saved.
What's an Alias?
An alias is basically a shortcut command. Instead of typing the full command, you create a shorter version that does the same thing.
How to Set It Up
Open your shell config file:
nano ~/.bashrc
# or if you use zsh:
nano ~/.zshrc
Add your aliases at the end:
# Git shortcuts
alias gs='git status'
alias ga='git add .'
alias gc='git commit -m'
alias gp='git push'
alias gl='git log --oneline'
# Navigation
alias ..='cd ..'
alias ...='cd ../..'
alias myproject='cd ~/projects/my-awesome-project'
# Common npm commands
alias ni='npm install'
alias nr='npm run'
alias ns='npm start'
# Quick docker
alias dps='docker ps -a'
alias dstop='docker stop $(docker ps -q)'
Save and exit (Ctrl+X, Y, Enter if using nano).
Then reload your shell:
source ~/.bashrc
# or
source ~/.zshrc
Real-Life Example
Before:
cd ~/projects/my-webapp && npm run dev
After:
mydev # That's it!
You just saved keystrokes and your carpal tunnel says thank you.
Pro Tips
- Keep it memorable - Use abbreviations you'll actually remember
- Don't override existing commands - Check before naming your alias
- Document complex ones - Add comments in your config file
- Share with your team - Add aliases to a dotfiles repo everyone can use
Bonus: Functions for Complex Tasks
If you need more than a simple shortcut, use a function:
# Create and navigate into a directory
mkcd() {
mkdir -p "$1" && cd "$1"
}
# Kill process by name
killport() {
lsof -ti:$1 | xargs kill -9
}
The Real Win
Every second counts when you're grinding. These tiny automation wins add up to hours of reclaimed time over a year. More time coding, less time typing the same stuff.
Start with 5 aliases today. You'll thank yourself tomorrow.
What's your favorite time-saving alias? Drop it in the comments! 👇
#happycoding
Top comments (1)
.