For a while, I've been wanting to be able to make Aliases for the terminal. An alias is a type of shortcut for the command line. For example, rather than typing...
killall Dock
...I might want to shorten it down to...
ka Dock
This makes it a lot quicker, and easier, to force quit applications from Terminal. Well, MacTips.org recently had an tip on this. And here's how you make an alias for the command line.
Step 1: Open Terminal.app (Applications>Utilities>Terminal.app
Step 2: Now that Terminal's open, we need to edit the .bashrc file in your home folder. To edit it in Pico, use:
pico ~/.bashrc
Step 3: Once the pico editor has opened, we need to add a shortcut. The format for a shortcut is:
alias shortcut="the_original_command"
So, to add a shortcut for killall, we would use:
alias ka="killall"
Step 4: We now need to close pico. To do this, hit the Ctrl-X (^X) keyboard shortcut. Then, type a "y". Finally, hit "Return" to save it as "~/.bashrc". As a note, you can see what you're doing with ^X, Y, Return, by looking at the bottom of the Terminal window.
Step 5: You need to "refresh" the .bashrc file in Terminal. To do this, type:
source ~/.bashrc
Step 6: Type in your new shortcut and test it out! Now, when I type...
ka Dock
...it will force the Dock to restart.
That's it! If you were wondering, I learned this from MacTips.org. Also, if you are having issues with it not working, make sure that you type in the quotes (") rather than copy/pasting them.
BTW, I will be traveling the next week (until the 31st) so I will not be posting tips at a consistent time like I try to. However, there should still be a new tip every day. (Except Saturday)
12/20/07
Adding Aliases For the Command Line
Posted by
Oliver
at
Thursday, December 20, 2007
Labels: Terminal
Subscribe to:
Post Comments (Atom)


2 comments:
Thanks for this. Reminded me that I could use pico to do this!
Thanks for the taking the time to do this, just helped me out.
Post a Comment