Linux aliases Introduction

The Linux alias command are replaces one string from the shell with another string.

It is a shell built-in command. It converts a complicated command into a simpler command or in other words, it creates a shortcut by replacing it with the simpler one.

alias’ in command line creates a temporary ‘alias’.

aliases command are temporarily only available until you exit the shell. It make permanent ‘alias’ store it in bash startup files.

Here : There will be no space on either side of (=) sign while typing ‘alias’ command. Quotes are necessary if there are more than one word in the string being aliased.

Sample syntax of alias :

alias <newName>=<command>                   (To create alias for commands)  
alias <newName>=<'command arg1 arg2....'>   (To create alias for more than one argument)  
alias <newName>=<'/home/student/path/...'>    (To create alias by a path)  

Creating an alias

Now we are going to use following options for creating an alias.

Creating alias for 'file' command as 'fi'
Creating alias for 'ls-l' command as 'll'
Creating alias with two arguments
Creating alias for a path

Creating alias for ‘file’ command as ‘fi’

Sample syntax of :

# alias <newName>=<command>  

Like example of :

# alias fi=file  

See your terminal after run the command, ‘file’ command is aliased as ‘fi’ through command “alias fi=file”.

Creating alias for ‘ls-l’ command as ‘ll’

Sample syntax of :

# alias <newName>=<'command'>  

Like example of :

# alias ll='ls -l'  

See your terminal after run the command, ‘ls -l’ command is aliased as ‘ll’ through command “alias ll=’ls -l’ “.

Creating alias with two arguments

Sample syntax of :

# alias <newName>=<'command arg1 arg2'>  

Like example of :

# alias both='ls sample example'   

See your terminal after run the command, ‘ls sample example’ command is aliased as ‘both’ through command “alias both=’ls sample example’ “.

Creating alias for a path

Sample syntax of :

# alias <newName>=<'/home/student/path/...'>  

Example:

# alias path='cd /home/student/Downloads/sample'  

See your terminal after run the command, ‘cd /home/student/Downloads/sample’ command is aliased as ‘path’ through command “alias path=’cd /home/student/Downloads/sample’ “.

How to remove alias

With the help of ‘unalias’ command you can remove created alias.

Sample syntax of :

# unalias <createdAlias>  

Like example of :

# unalias c  

See your terminal after run the command, alias ‘c’ work as ‘cat’ command. Now removing ‘c’ by the command “unalias c” we got an error message.

If you understand this article now you can practice your terminal. When you practice more and more then you can learn something. With the best wishes. Good Luck.