I find there are a lot of commands I run routinely. Some of which are pretty long strings that are thrown together in order to find what can, at times, be a small piece of information. Or, I might routinely log into a server and want to trim down the command required to do so. Let’s take an example of this in using the open command to vnc into a server. The command to open a server in this fashion would be (assuming a server name of mail.mygroup.mycompany.com, a username of krypted and a password of mypass):
For this exercise we’re going to be saving the above command into a file in clear text and so we are not going to actually embed the password. We’re going to use the alias command to create an alias, which can then be called on as a normal command, called vncmail. This way, that’s all we have to type in a terminal window to execute the string from the command above. Do this by using alias then the command you would like to have, followed by an equals sign (assuming bash here, btw) and then a quoted command:
alias vncmail='open vnc://mail.mygroup.mycompany.com'
Once you close your bash shell this alias will disappear. So let’s make it permanent by placing it into the .bash_profile file in your home directory. First, if it’s not there, we’ll create the .bash_profile:
Then add the alias line from above into the ~/.bash_profile file. Then make sure this file roams using a mobile home for your admin account. Then, whichever system you sit at, you can quickly VNC, SSH or even ‘dscl . read /Users/localadmin’ or whatever. Lots of stuff you can do with aliasing commands. One of my favorite is ‘/Applications/Utilities/Network\ Utility.app/Contents/Resources/stroke ODServer 389 389′ to do a quick port scan of an LDAP server over port 389 (or 636 if you’re using SSL). Anyway, hope this saves you as much time as it’s saved me over the years!
- None Found