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




Recent Posts:




Code2care is an initiative to publish and share varied knowledge in programming and technical areas gathered during day-to-day learnings and development activities.

Students and Software Developers can leverage this portal to find solutions to their various queries without re-inventing the wheel by referring to our easy to understand posts. Technical posts might include Learnings, Video Tutorials, Code Snippets, How Tos, Blogs, Articles, etc.