Monday, December 3, 2007

HowTo: Linux Aliasing Aliases

Here's a quick tip on linux alias command, definitions and usage.

In Linux, an alias is basically used to duplicate a name or a command. Duplicating a linux alias or a linux command gives comfort and convinience in some reasons. There are lots of linux command that are hard to remember and too long to type in terminal. Others linux commands are seldomly used and not easy to remember. There are times that you frequently use the same command parameters and command options on issuing a particular command, linux command aliasing can be of benefit and helpful on these scenarios and cases.

More Alias Usage

If you wish to shortcut a certain command, we can use the same approach like the ones shown below:

~~~~~~~~~~~~~~~~~~~~~~~
# alias c='cat'
# c testfile.txt
~~~~~~~~~~~~~~~~~~~~~~~

From the above usage, issuing 'c' alone would be equivalent as issuing a cat command.

Another approach. Aliasing can be of handy on a scenario where in you frequently CD on a particular folder to update and check for some files upon your superior's request.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# alias goman=’cd /home/north/priority10/web-customers/wallstreet/www/public_html/admins
# goman
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Changing to a folder location of cd /home/north/priority10/web-customers/wallstreet/www/public_html/admins on frequent basis is now convenient using the alias goman as shown above.

Another alias example. If we always use ls command with -la parameter, aliasing it as follows:

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# alias lls=’ls -la’
# lls
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Issuing lls would be just fine to get the same command result.

Now, let us assume that nobody should use 'reboot' command

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# alias reboot='reboot command not found'
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

The next time a user executes reboot command, the user would be prompted that reboot command does not exist.

Note that these alias commands are only effective on current login sessions. In order to make it permanently, you need to edit and save it as user's .profile file located from user's home folder. A system wide alias can also be done and included to /etc/profile file.

Issuing alias without any parameter would list down all aliases aliased with alias.

In order to remove an existing session alias, you can use the unalias command.

For example , to remove an alias gogogo, simply

~~~~~~~~~~~~~~~~~~~~~
# unalias gogogo
~~~~~~~~~~~~~~~~~~~~~

Alternatively, you can remove the alias by modifying .profile or /etc/profile file(s).

Alias linux command is simple and get things done easier and faster. Saves more effort and time with your finger tips and tik-taks with the keyboard as well.

HTH

0 comments:

Sign up for PayPal and start accepting credit card payments instantly.
ILoveTux - howtos and news | About | Contact | TOS | Policy