How to create alias in macOS


Alias comes very handy to create shortcuts for complex or large commands you use in Terminal, it can help you improve your productivity (and do not need to remember that complex command you always forget :D)

Creating alias on macOS
Creating alias on macOS
  1. Open Terminal (this article is based on Zsh shell as being default one for macOS as of 2021),
  2. Now type ~/ to go to your user directory
  3. Do a ls -a and check if you have the .zshrc file, if not we will create it,
  4. run command: nano ~/.zshrc
  5. Now add your alias in this file one per line, example:
  6. alias hello=ls
    alias allfiles='ls -a ltrh'

    ✏️ Note that if there is a space in the the command, you should surround it with single quotes. There should be no space between the alias name and equals sign and its value.

  7. Now press Command + X to quite nano and click Y to save the file.
  8. To apply the changes type command: source ~/.zshrc
  9. Now try the command from any location in your terminal, they should work!

⭐ Check out some examples aliases that you can create to improve your productivity!: Zsh Shell: Custom alias that you may find useful