Skip to content

How to set an alias in a macOS or Linux shell

New Course Coming Soon:

Get Really Good at Git

How to set an alias in a UNIX environment, including Bash, Zsh, Fish on both macOS and Linux

Sorry, no Windows instructions as I don’t use Windows. Use Google if that’s the OS you use.

I found a funny post on Reddit that highlights how we, as developers, can lose productivity over the small things, like typos:

Set git aliases

I don’t have this set up, as I mostly use a GUI for Git (GitHub Desktop). But I use other aliases. Most notably ll instead of ls -al.

How do I set up an alias in the terminal?

Also check my guides how to use the macOS terminal, the Bash shell and the Bash scripting tutorial.

I said macOS in the title, but this works also on Linux of course.

Here’s the syntax:

alias <newcommand>='<old command>'

Here’s the example I mentioned above:

alias ll='ls -al'

This works in Bash, Zsh, Fish shell and others too.

If you write this in your shell, from now on ll will be a new available command in the console.

Note: this alias is going to be valid for the entire session, which means until you close the shell, or you restart the computer, whatever comes first.

To persist the aliase, so you can use them any time in the future, you need to add it to the configuration file for your shell.

If you use Bash, that’s the .bash_profile in your home folder. It’s an invisible file, so you might need to open it with the terminal rather than the Finder:

code ~/.bash_profile

~ always points to your home folder path

(assuming you have VS Code installed, which provides the code command).

If ~/.bash_profile does not exist, you can create it, and the shell will pick it up. You can also use the ~/.bashrc file, if present.

For licensing purposes, macOS Catalina comes with a new shell by default, called Zsh. In this case, the configuration file is in the ~/.zshrc file, still in your home folder.

code ~/.zshrc

The fish configuration is stored in ~/.config/fish/config.fish, but you’ll most likely configure it via the fish_config command.

Are you intimidated by Git? Can’t figure out merge vs rebase? Are you afraid of screwing up something any time you have to do something in Git? Do you rely on ChatGPT or random people’s answer on StackOverflow to fix your problems? Your coworkers are tired of explaining Git to you all the time? Git is something we all need to use, but few of us really master it. I created this course to improve your Git (and GitHub) knowledge at a radical level. A course that helps you feel less frustrated with Git. Launching Summer 2024. Join the waiting list!

Here is how can I help you: