Exploring alias in Linux

Alias are greater help for mankind 🙂 in linux system where you can transform any complex command to simple one. Let’s say you want to find a list of files which has some specific pattern in a directory. It usually done using grep command with options for recursive and case sensitive.

Following command searches for super/SUPER in the Documents directory.

>> grep -ri “SUPER” /home/codeexpose/Documents 

Using alias we can transform this whole command to something meaningful and simple

>>search_dir  “pattern”  <dir>

Which alias I found it very useful

There are certain command which makes me tired of typing like alphanumeric commands. Am talking about ssh, some case of ssh needs ip address instead of machine name to initiate a connection.  For example to create a ssh connection to other machine in linux. I have to type

>> ssh user@10.x.x.x

The above command opens ssh shell for 10.x.x.x machine. Like as i said typing this sometime takes up some brain and worse if it needs some additional option to be enabled.  So i made alias and named it as connect_machine1 . Whenever i need a connection i just type connect_machine1 in terminal as simple as that.

>>connect_machine1

Other helpful alias i use are

alias update=’sudo apt-get upgrade’
alias install=’sudo apt-get install’
alias meminfo=’free -m -l -t’

How to create alias in linux ?


It’s easy to create an alias in linux. It also act as a command and it maintained over session basis. If we declare alias in one terminal and it gets un aliased if terminal gets killed. If you want to have permanently then keep alias in .bashrc file which should be available in home directory.

The syntax of alias is simple

>> alias new_command=’original_command’

alias, is executable and mostly available in /usr/bin/ .

new_command, is a new command used to replace the original command. One thing to note is it can’t be more than one word.

Original_command, is a orignal command which needs to be replaced.

What not possible with alias ?

alias will not help with command which has more than one word. Let take an example of listing all the executable file, text file, object file in the directory. It may need different alias name for different kind of file. That makes the alias complex, so how this can be solved. This can be solved using bash functions. We can declare bash function named as find_file and we can give the type of file as argument. the function should have a business logic to list the file based on the argument

So, what’s your favourite alias comment below and let us know.

Leave a Reply

Your email address will not be published. Required fields are marked *