25 Mar 2024 ~ 1 min read

How to Add Aliases to the Mac Terminal

I don’t think I could live without all my alias commands. Most of the time, I add ones for Git commands, but every once in a while, you run into a complex command you need for Docker or a convoluted development process, like exposing a port for an Android device.

That's when they come in really handy. Anyhow, here's how you can create them on a Mac.

Creating Aliases

  1. Open Terminal on your Mac.
  2. Type the following command if you use VS Code: code ~/.bash_profile. You can use any code editor you want; that is just my preferred option.
  3. This will open the .bash_profile file in your text editor.
  4. Now start adding aliases following this format: alias [shortcut]='[command]'.
  5. Replace [shortcut] with the shortcut you want to use for the command, and [command] with the command you want to execute.
  6. Press save to apply your changes.
  7. Type source ~/.bash_profile in your terminal to reload the file and apply the changes.

That's it! You've just created an alias for a terminal command. Now, whenever you type the shortcut, the command will be executed.


Here are some examples of aliases you can create to make your terminal commands faster and simpler:

  • alias ll='ls -alh' - This creates an alias for the ls -alh command, which lists all files in a directory in a long format with human-readable file sizes.
  • alias gs='git status' - This creates an alias for the git status command, which displays the status of your Git repository.
  • alias vs='code .' - This creates an alias for opening the current directory in VS Code.

Now you can create as many as you want and speed yourself up, reducing the number of complex commands you need to remember.

Well, that’s it. Talk to you later!