Shell Scripting: Creating Aliases

Join the AI Workshop to learn more about AI and how it can be applied to web development. Next cohort February 1st, 2026

The AI-first Web Development BOOTCAMP cohort starts February 24th, 2026. 10 weeks of intensive training and hands-on projects.


Using aliases we can set up shortcuts for common commands.

Defining Aliases

Use this syntax:

alias <newcommand>='<command>'

Example:

alias ll='ls -al'

Now typing ll runs ls -al.

This works in Bash, Zsh, and Fish shell.

Persisting Aliases

If you define an alias in the shell, it only lasts for the current session. To make it permanent, add it to your shell configuration file:

  • Bash: ~/.bashrc or ~/.bash_profile
  • Zsh: ~/.zshrc
  • Fish: ~/.config/fish/config.fish

Open the file:

code ~/.bashrc

Add your aliases:

alias ll='ls -al'
alias gs='git status'
alias gc='git commit'

Apply changes without restarting:

source ~/.bashrc

Useful Alias Examples

Git shortcuts:

alias gs='git status'
alias gc='git commit'
alias gp='git push'
alias gl='git log --oneline'

Navigation:

alias ..='cd ..'
alias ...='cd ../..'
alias home='cd ~'

Safety nets:

alias rm='rm -i'  # confirm before deleting
alias cp='cp -i'  # confirm before overwriting
alias mv='mv -i'  # confirm before overwriting

Quotes Matter

Be careful with quotes when using variables:

alias lsthis="ls $PWD"   # $PWD resolved when alias is defined
alias lscurrent='ls $PWD' # $PWD resolved when alias is used

With double quotes, the variable is resolved at definition time. With single quotes, it’s resolved at invocation time.

If you navigate to a new folder:

  • lsthis still lists files from where you defined the alias
  • lscurrent lists files from your current folder

Removing Aliases

Use unalias to remove an alias:

unalias ll

Viewing Aliases

List all defined aliases:

alias

Or check a specific alias:

alias ll

Lessons in this unit:

0: Introduction
1: Introduction to Shells
2: Bash Basics
3: Writing Shell Scripts
4: Variables and Environment Variables
5: Loops and Arrays
6: Shell Script Functions
7: ▶︎ Creating Aliases
8: Tips and Tricks
9: The Fish Shell
10: Persist aliases and other configuration in Fish Shell
11: How to add a path to Fish Shell
12: Fish Shell, how to avoid recording commands to history
13: Fish Shell, how to remove the welcome message
14: How to replace all filenames with space with underscore using a shell script
15: How to update all npm packages in multiple projects that sit in subfolders