[SLUG] Aliases

Paul Teasdale pdt at rcsuk.fsnet.co.uk
Thu Apr 3 18:01:00 BST 2003


During the IRC meet on 2/4/2003 Al (on behalf of Mark) asked about setting
up aliases under Linux. After  a small mix up on my behalf I dicovered they
were talking about command line aliases and not mail aliases. I thought I
would just post this information on to the mailing list for everybodies
benefit and to correct as slight inconsistency that I told Al and Mark
regarding global aliases.

Firstly the difference between command line aliases and mail aliases are as
follows:

With a mail alias you can divert all the mail bound for one user to another.
So, for example, you can divert all mail bound for the root user to your
desired user account. The file to do this is located in /etc and is called
aliases.

Command line aliases offer a method where by you can assign a name (a.k.a
alias) to a commonly used command and use the name in place of the command.
This sounds a bit pointless but if it's a long command with loads of command
line switches it can save a load of typing. The format of the alias command
is as follows:

alias newname='command'

where 'newname' is the new alias name for the command
and 'command' is the actual command line instruction that you want to alias
Also note that the single quotes around command ARE required

Example:

alias la='ls -la'

will create an alias called la. Typing la at the command prompt will have
the effect of calling the command ls -la. BTW ls -la lists all the files
(including hidden files) in the current directory :)

It is posible to change your personal ~/.bashrc file to automatically setup
aliases everytime you start a new shell. In your home directory edit .bashrc
and add as many alias commands as you wish at the end of the file.

Under SuSE 8.1 you can create a file called .alias in your home directory
because there is a line in .bashrc that calls this file if it exists.

A word of warning: aliases will only become available to any new shells and
not the current shell you are working in because the .bashrc file is only
called once when the shell is started. You will therfore need to start a new
shell to see of your aliases have worked.

Adding aliases to your local .bashrc file will only apply to your login and
not other logins.

If you want to create global aliases I told Al and Mark a slightly
unofficial method although my method also works but it's not the official
method. I will explain the official method first:

In /etc edit the file bashrc (note no starting dot as in the local one) and
add aliases here. I have NOT confirmed this but under SuSE 8.1 there may be
a file called bashrc.local or you may need to create it. You should put any
aliases in bashrc.local. Why? This is a SuSE convention (don't know about
other distros) and has two reasons:

1) It keeps customistations separate
2) When upgrading the OS your customisations will not be over written with a
new bashrc file.

Finally a word of warning (again): global aliases only become available when
you login in as that is the only time /etc/bashrc is called so remember to
log out and back in to activate you changes.

The Paul method is as follows (slightly unofficial but works
never-the-less).

In /etc edit the file called profile (or profile.local under SuSE for the
above mentioned reasons) and add aliases here. Otherwise this method is
exactly the same as the offical method with all the same warnings.

Finally:

Check out http://www.tldp.org/HOWTO/Config-HOWTO/config.html if you need
further examples and explanations.

Regards,

Paul






More information about the Scarborough mailing list