☕ Buy a Coffee
Home / Productivity & Coding

Set Up an 'Alias' in Linux/Mac for Long Commands

Save hours of typing by shortening verbose Docker, Kubernetes, and Git commands into intuitive 2-letter terminal shortcuts.

Sachin Siju
Sachin Siju
Lead Systems Engineer & Tech Blogger
Jul 02, 2026 3 min read
Set Up an 'Alias' in Linux/Mac for Long Commands

Stop Retyping the Same 40 Characters

If you spend your day in a terminal running Docker, Kubernetes, or Git commands, you have almost certainly typed something like kubectl get pods --all-namespaces or git log --oneline --graph --all dozens of times in a single session. A shell alias lets you bind that entire command to a short word or two, permanently, with zero performance cost.

Finding Your Shell Configuration File

Aliases are defined in your shell's startup file, which loads every time you open a new terminal. Which file you edit depends on your shell:

  • Bash (default on many Linux distros, older macOS): ~/.bashrc (Linux) or ~/.bash_profile (macOS)
  • Zsh (default on macOS since Catalina, and popular on Linux): ~/.zshrc

Check which shell you are running with:

echo $SHELL

Creating a Temporary Alias

Before making anything permanent, you can define an alias directly in your current terminal session to test it:

alias gs='git status'

Type gs and press Enter — it runs git status exactly as if you had typed it out. This alias disappears the moment you close the terminal, which makes it a safe way to experiment with names before committing to them.

Making Aliases Permanent

Open your shell config file in a text editor:

nano ~/.zshrc

Add your alias definitions anywhere in the file, one per line:

alias gs='git status'
alias gp='git push'
alias gl='git log --oneline --graph --all'
alias dcu='docker compose up -d'
alias dcd='docker compose down'
alias k='kubectl'
alias kgp='kubectl get pods --all-namespaces'

Save the file, then reload your shell configuration without closing the terminal:

source ~/.zshrc

Your new aliases are now available in every terminal session going forward, including new tabs and windows you open.

Aliases With Arguments

Plain aliases are simple text substitutions — they cannot accept positional arguments in the middle of the command the way a function can. If you need an alias that takes a parameter partway through, define a shell function instead and put it in the same config file:

gcm() {
  git commit -m "$1"
}

Now gcm "fix login bug" runs git commit -m "fix login bug". Functions behave like aliases for everyday use but support real arguments, conditionals, and multi-line logic.

A Practical Kubernetes and Docker Alias Set

These are common enough across sysadmin and DevOps workflows to be worth adding as a starting point:

alias k='kubectl'
alias kgp='kubectl get pods'
alias kgs='kubectl get svc'
alias kdp='kubectl describe pod'
alias klf='kubectl logs -f'
alias dps='docker ps'
alias dpsa='docker ps -a'
alias dimg='docker images'
alias dprune='docker system prune -f'
Tip: Keep the two-letter naming pattern consistent — first letter(s) for the tool, second for the subcommand (g for git, k for kubectl, d for docker). It makes new aliases predictable enough that you can often guess one correctly before you have even defined it.

Listing and Removing Aliases

To see every alias currently active in your shell, run:

alias

To remove one for the current session only, use unalias:

unalias gs

To remove it permanently, delete or comment out its line in ~/.zshrc (or ~/.bashrc) and reload the file with source.

Avoiding Naming Collisions

Before picking a short alias, check that it does not already shadow a real command you occasionally need in its original form:

type ls

If type reports that a name is already an alias, function, or binary, either pick a different short name or, if you intentionally want to override the built-in (a common example is alias ls='ls -la'), that is fine — just remember the original behavior is now hidden behind your new default. You can always bypass an alias for one call by prefixing a backslash: \ls runs the real, unaliased command.

Syncing Aliases Across Machines

If you work across multiple servers or machines, keep your alias definitions in a dotfiles repository on GitHub and symlink ~/.zshrc (or source a separate ~/.aliases file from it) so a fresh machine setup is one git clone away from having your full shortcut set back.

Featured Infrastructure Partner

Deploy on High-Performance Hostinger Cloud

Get up to 75% OFF + free domain & SSL. Powering xube.me's sub-second response times.

Claim Discount ↗

Discussion & Insights

Related Technical Essays