Linux alias command tutorial

The Linux alias command is another utility to make working in Linux command line easier. We can make an alias for a long Linux command with options and arguments to a simple command. The alias command is very useful for a Linux system administrator which has lots of routine jobs such as checking log files, clean hard disk space, and so on. Let's see some examples of alias command and the usage.

If you ever used Red Hat Linux in the past and now using Slackware or Ubuntu, you probably miss the 'll' command which is a short command for 'ls -l'. If you like the 'll' command and prefer to have it in your Slackware or Ubuntu, you can have it using the Linux alias command. Here is the example on how to create an alias of 'ls -l' command to 'll':

[email protected]:~# alias ll='ls -l'

Test it now to see if it works:

[email protected]:~# ll
total 4
-rwxr-xr-x 1 root root 77 2009-10-26 17:36

You can check other alias which comes default with your Linux distribution:

[email protected]:~# alias
alias ll='ls -l'
alias ls='ls --color=auto'

Create how many alias you need especially the most used command with many options.

If you need to remove any alias, you can do that with the 'unalias' command. Here is the example:

[email protected]:~# unalias ll
[email protected]:~# alias
alias ls='ls --color=auto'
[email protected]:~#

You can also personalize your Linux environment using Linux alias command and put all aliases you add in a file. What you need to do is edit the Alias section in the .bashrc file. If you are using Ubuntu Desktop, here is an example of .bashrc file and how to edit the Alias section in the file:

Open .bashrc file with text editor of your choice. Here is an example on how to use vim text editor to edit the file:

[email protected]:~$ sudo vim .bashrc

Find the Alias section and uncomment the line in red below:

# Alias definitions.
# You may want to put all your additions into a separate file like
# ~/.bash_aliases, instead of adding them here directly.
# See /usr/share/doc/bash-doc/examples in the bash-doc package.

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

# enable color support of ls and also add handy aliases
if [ -x /usr/bin/dircolors ]; then
eval "`dircolors -b`"
alias ls='ls --color=auto'
#alias dir='dir --color=auto'
#alias vdir='vdir --color=auto'

#alias grep='grep --color=auto'
#alias fgrep='fgrep --color=auto'
#alias egrep='egrep --color=auto'

# some more ls aliases
#alias ll='ls -l'
#alias la='ls -A'
#alias l='ls -CF'

Save the changes and quit text editor.

Create a new file called .bash_aliases.

[email protected]:~$ sudo vim .bash_aliases

In the new file, add aliases that you want and save. The changes will take effect the next time you open command line terminal.

That's all.

Back to Other important Linux basic commands main page.

Add new comment