If you’re like me, and use a few terminal commands on a daily basis, and you hate typing them. This tip is for you. This is an example of creating an “alias” for a frequently used, or hard to remember command. In this example I will be creating a “shortcut” to a ssh session. However, you can type any command between the quotes in step 3.
- While inside your home directory (/Users/yourusername).
- Type nano .bashrc this will open the text editor and you will see maybe a few lines, maybe nothing.
- Type alias shell=”ssh user@server” (replace “shell” with whatever you want your alias to be)
- Hit ctrl+x and then y and return to save this.
- Type source ~/.bashrc - This will reload the .bashrc for your shell.
- After you do everything you need to add source ~/.bashrc to .bash_profile in /Users/yourusername/ to make sure it’s loaded at login.
Now, when you open a terminal, just type shell and your ssh session will start. I use this for everything, I have aliases for ten ssh shells, two Macfuse mounts, and I use the alias r for screen -r to quickly attach back to a screen session that has detached.

Trackback
[...] Astuce pour Terminal (Mac): créer un alias de commande. [...]
December 22nd, 2007 at 9:50 am