What I Wanted to Do
Typing git status or docker-compose up -d in full every time got tedious fast.
Adding aliases to .bashrc or .zshrc lets you register short custom commands without installing anything.
Basic Alias Syntax
Add alias definitions to ~/.bashrc (for bash) or ~/.zshrc (for zsh):
# Add to ~/.bashrc or ~/.zshrc
alias gs='git status'
alias gp='git push'
alias ll='ls -la'
alias dc='docker-compose'
Apply the changes without restarting the terminal:
source ~/.bashrc
# or
source ~/.zshrc
Useful Alias Examples
Git Shortcuts
alias gs='git status'
alias ga='git add .'
alias gc='git commit -m'
alias gp='git push'
alias gl='git log --oneline --graph'
alias gd='git diff'
Docker Shortcuts
alias dc='docker-compose'
alias dcu='docker-compose up -d'
alias dcd='docker-compose down'
alias dps='docker ps -a'
alias drm='docker rm $(docker ps -aq)'
General Linux Shortcuts
alias ll='ls -la'
alias la='ls -A'
alias ..='cd ..'
alias ...='cd ../..'
alias grep='grep --color=auto'
alias mkdir='mkdir -pv'
Using Shell Functions for Multi-Step Commands
When a single alias is not enough, define a function instead:
# Create a directory and immediately cd into it
mkcd() {
mkdir -p "$1" && cd "$1"
}
# Git add + commit + push in one command
gacp() {
git add .
git commit -m "$1"
git push
}
Functions go in the same .bashrc / .zshrc file as aliases.
Check What Aliases Are Defined
# List all current aliases
alias
# Check a specific alias
alias gs
Common Pitfalls
- Forgetting to run
source ~/.bashrc— changes won’t take effect until you reload or open a new terminal - Editing
.zshrcwhen your shell is actually bash (check withecho $SHELL) - Naming an alias after an existing command silently overrides it (use
which dcto check first) alias gc='git commit -m'needs the message as an argument: use it asgc "your message"- On some servers the login shell is
/bin/sh, so.bashrcmay not be loaded automatically
Related Articles
- Linux Basic Commands Cheatsheet (ls/cd/mkdir/rm)
- SSH Basics on Linux (How to Connect to a VPS)
- How to Use ~/.ssh/config to Simplify SSH Connections
- How to Schedule Cron Jobs on Linux for Automated Task Execution
- Linux Process Management (ps/kill/top)
Recommended Cloud Hosting
Looking for reliable cloud infrastructure? Check out these developer-friendly services.
- Cherry Servers - High-performance VPS and dedicated servers
- Cloudways - Managed cloud hosting for developers