Aliases
Aliases are a simple way to create short, memorable shortcuts for longer shell commands. They're useful for speeding up repetitive tasks and making commands easier to type.
Quick reference
- List currently defined aliases:
- alias
- Create a temporary alias (current shell session only):
- alias ll="ls -la"
- Remove an alias in the current session:
- unalias ll
Make aliases persistent (zsh / bash)
- Open your shell config file (for zsh, typically
~/.zshrc; for bash,~/.bashrcor~/.bash_profile):
nano ~/.zshrc
- Add your alias lines, for example:
alias ll="ls -la" alias gs="git status"
- Save the file and reload the config (or open a new terminal):
source ~/.zshrc
Fish shell
Fish uses a different syntax and has a builtin helper:
alias ll='ls -la'
functions --save ll
Notes and tips
- Quote complex commands. If the command contains pipes, semicolons, or expansions, wrap it in single or double quotes.
-
For commands that require arguments or complex logic, prefer a shell function in your rc file instead of an alias. Example (zsh / bash):
mybackup() { rsync -av --progress "$1" /backup/"$(basename "$1")" }
-
Aliases created with the
aliascommand without adding to your rc file are temporary and only last for the current shell session. - To see where an alias comes from, search your dotfiles (e.g.,
grep -R "alias ll" ~).
Removing aliases permanently
-
Remove the alias line from your rc file (e.g.,
~/.zshrc) and reload the shell: -
Edit
~/.zshrcand delete or comment out the alias line. - Run
source ~/.zshrcor open a new terminal.
GMP (project-specific shortcuts)
Here are two example aliases used in my GMP workflow. Put these in your ~/.zshrc or project-specific rc file.
-
bts — shorthand for connecting to BTS (replace with the real host or ssh config alias):
alias bts="ssh bts"
-
cpc — connect to the control computer:
alias cpc="ssh control-computer"
If you use SSH config (~/.ssh/config) you can set Host entries and then use short ssh commands in aliases without long hostnames or options.
Examples — full workflow
-
Add aliases to
~/.zshrc:alias ll="ls -la" alias gs="git status" alias bts="ssh bts"
-
Reload your shell:
source ~/.zshrc
-
Use the alias:
ll
Troubleshooting
- If an alias doesn't appear after you add it, verify you edited the correct rc file for your shell and that you ran
source. - If a command seems to ignore an alias, check for a function or executable with the same name. Use
type nameto inspect.
Short summary
- Use
aliasto create quick shortcuts. - Put persistent aliases in your shell rc file (e.g.,
~/.zshrc). - For anything that needs arguments or conditional logic, prefer a shell function.