OSX Terminal Fun IV: Using aliases

term_icon.jpgUsing aliases in your shell help spare you from typing out frequently used but long commands such as:

	% ls -ohS --color=auto

There are a few ways to customize your aliases in MacOS X, but the right way™ is to create a few custom files under:

	~/Library/init/tcsh/

Now, in your finder click the home icon, and go to the Library folder, then look for a directory called "init" within it, and within the "init" folder look for one called "tcsh". You need to be looking in your user library, not the OSX library.

You may not have them- if you don't see them, use the following commands:


	% mkdir ~/Library/init/
	% mkdir ~/Library/init/tcsh/

You're directories are all there, now all you have to do is create the aliases.mine file which tcsh will read upon login, and load up your aliases for use.

	% pico -w ~/Library/init/tcsh/aliases.mine

Since the aliases.mine file doesn't exist, you're creating it by using the above command. Now you'll want to copy and paste the below into it:

alias l 'ls -ohU --color=auto'
alias ls 'ls -ohS --color=auto'
alias . 'cd ..'
alias p 'pico -w'
alias t 'top -d'

The syntax for aliases is a little different from linux, where it would normally look something like alias ls="ls -lAo". These are just a few to get you started, you can basically add anything you want in here... it can make you a lot more efficient, especially in used in conjuction with shell scripts.

Hold down the control key and press the "x" key, type yes when prompted to save, then hit return again when it shows you the filename of aliases.mine.

Close the window, create a new one and type the "l" key (l as lucky). You should now see unordered colored output whenever you hit "l", and will move up a directory when you type "." and "top -d" whould run when you type "t".

If you aren't happy with my default aliases, from the terminal type:

	% man ls

Look up the options, and add/remove to the aliases.mine file until it feels like a good fit for how you work.

Aliases are just a godsend- especially if you do things like SSH to login to servers remotely fairly frequently, or constantly type the same commands or go to specific directories all the time. Look up how to generate a private key for your server, which will allow you to login without a password. Create an alias called ssh1 or something with the command, and boom you're in.

To see all of your defined aliases while you're working, simpy type:

	% alias
yummy alcohol posted button Posted by drunkenbatman
    April 25, 2003, at 03:11 AM


Comments (4)




Post a comment



Anonymous comments are allowed, but please enter something for a name.

And do endeavor to appear sane.









Remember personal info?