MAC OS aliases

Are you using a Mac? Tired of typing long commands with many parameters again and again? Well, you can define aliases.

This recipe is used in courses IDATA2301 Web technologies and IDATA2306 Application Development at NTNU, campus Aalesund.

Instructions:

  1. You need to know the command you will want to make a shortcut (alias) for. For example, you may log into your server using SSH with the following command:
    ssh -i ~/.ssh/my-secret-key.pem ubuntu@my-server-ip
  2. The aliases are defined in the file ~/.zshrc. You need to edit that file and put your aliases there. To edit the file, run the following command in the terminal:
    nano ~/.zshrc
  3. Each alias in that file is defined as a line in the following format:
    alias youraliasname='the code you want to execute'
    For example, if you want to make a shortcut named ssh-into-server which will execute the command ssh -i ~/.ssh/my-secret-key.pem ubuntu@my-server-ip, then you add the following line to the file:
    alias ssh-into-server='ssh -i ~/.ssh/my-secret-key.pem ubuntu@my-server-ip'
  4. Save the file and exit the editor: press Ctrl+X, then Y, then Enter.
  5. Close all terminal windows (to force import of the aliases next time you open a new terminal window).

That's all, Folks! From now on you can use the ssh-into-server command instead of the long command with all the parameters.