OSX Terminal Fun IV: Using aliases
Using 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
Comments (4)
Posted by: drunkenbatman at April 29, 2003 04:14 PM
to use ssh without a password, either via an alias or a script (ie, if you're using scp to transfer files) you have to first generate a key, and upload that to the host box. i'll put that up as time allows.
Posted by: Tom at May 14, 2003 11:42 PM
Aliases are a lot easier to add if you just make a .tcshrc file in your home directory. It's the UNIX way, and also you can stick a bunch of other config info in there for your shell :)
Nice blog :)
Posted by: drunkenbatman at May 15, 2003 11:20 AM
Ah, you're right in that you don't have to use /library/init/tcsh/, and when I'm using linux such you're right in that you'd want to have a ~.bashrc and such.
Apple just reccomends that for OSX you use the scheme of ~/Library/init/tcsh to make things "cleaner"... i can see their point in that it does make a backup and such easier for me, just grab the ~/Library/ folder and I have most of the system config files I need... and the niceties of the other stuff in the examples gives you autocomplete, etc.








I got SSH working with an alias but when I try to use it with my script it doesnt work cus it doesnt authent and i cant make it work by giving the password in the alias?