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

Try Out Code2care Dev Tools:


Android Java Linux Microsoft Google Python macOS Notepad++ Microsoft Teams CSS PHP SharePoint Html Linux C Programs Bootstrap jQuery Sublime Android Studio Facebook Eclipse WhatsApp News MySQL Json HowTos JavaScript FTP S3


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, Tutorials, Trouble-Shooting steps, Video Tutorials, Code Snippets, How Tos, Blogs, Articles, etc.
🎉 We are celebrating the 10th years of Code2care! Thank you for all your support! We hope we made a difference.
We strong support Gender Equality & Diversity.

We stand in solidarity with Ukraine - Make a donation to UNHCR -