working with aliases

Submitted by aleswa on Thu, 2008-09-25 22:05.

Aliases are custom commands which can be used to make the work with the shell easier. For example, if your current working directory is /usr/bin and you want to quickly go to /var/cache/apt/archives you can do a "cd /var/cache/apt/archives" command. If you want to save time, you may want to type only a command such as "cache" or "archives". This is where aliases come to help.

There are two ways to create aliases.
1. Add aliases directly in your ~/.bashrc file. The format should be:

alias name='command'

You can add for example something like:

alias ll='ls -l'
alias dld='cd ~/Downloads'

Next time you'll type "ll" the "ls -l" command will be executed.

2. The second method lets you make a separate aliases file, so you won't have to put them in .bashrc, but to a file of your choice. First, edit your ~/.bashrc file and add or uncomment the following lines:

if [ -f ~/.bash_aliases ]; then
. ~/.bash_aliases
fi

Save it and close the file. After that, all you have to do is create a ~/.bash_aliases file and add your aliases there, with the same format specified in the first method.

source: http://my.opera.com/Christmas/blog/show.dml/356149

( categories: )