An alias can be a simple commmand substituted for a long command. Take ls -la for example. How many times do you type that in a session? I mean, those keys are just gonna wear out aren't they..
To create an alias command in BASH, type:
alias l="ls -laG"
Go on, try it. What this says is, create a command called l and use it to represent the ls -laG command and switches.
Then next time you need a directory listing, just type l instead. The extra G gives directories their own shade of royal blue. Just like Linux.
Oh, one more thing. The alias lasts for the duration of the login. To make it permanent, edit the relevant .profile file for that user. Changes to the profile take effect next login.
Now M'man Brad and I have noticed that the above doesn't work from .profile
when you su
. This can be from an ssh
session or from the console itself. It works if you log in as root
at the console, or any other user with the alias in their .profile
, but not after you su
We couldn't find an answer so we put this to some of the boys, specifically Nick 'Fratboy' Fratangelo, Ian 'The Expert' Wells and Dan-The-Man. Dan just laughed and walked away but that's just Dan - bloody weirdo! But Nick and Ian were intrigued by the dilemma. Well we couldn't find where BSD keeps the .profile
information cached and we couldn't make it work, but the boyz did come up with a workaround.
Instead of an alias, create a script and put it in /bin
which is in the system path, so you won't have to preceed it with the obligatory "./"
and where it will be accessible to all users. In the following example, we made a script called 'l'..
..and finally make it executable..
chmod 755 l
So now when you type l
from wherever you are in the directory tree, it runs the script and you get an ls -laG
- just like an alias. Clever.