Friday, 12 February 2016

How To Use Alias In Unix/Linux

Many a times we face situation where we have to move in different directories to analyse the issue or checkout the multiple objects involved. At times it becomes very lengthy and time consuming as you have type a lot to change the directories involved.

For example, let say you have following directories available for your project:
  • Source File Directory which keeps the source file
  • Target File Directory which keeps the files generated after some processing.
  • Scripts, executable logics which perform some action
  • Log File Directory, keeps the log of all the activities
Now, if you have are doing some impact analysis it will become very time consuming to navigate in these directories. Alias command provides solution of such situations. How? Let see...!!

Source File Directory: /home/baba/kw/SourceFiles/ABC
Target File Directory: /home/baba/kw/TargetFiles/ABC
Script File Directory: /home/baba/kw/Scripts/ABC
Log    File Directory: /home/baba/kw/Logs/ABC

alias Source='cd /home/baba/kw/SourceFiles/ABC'
alias Target='cd /home/baba/kw/TargetFiles/ABC'
alias Script='cd /home/baba/kw/Scripts/ABC'
alias Log='cd /home/baba/kw/Logs/ABC'
  
Now if you type log at terminal, it will directly take you to the log directory, similarly if you want to go to source directory while you are still in log directory, just type source
you will be in source file directory.

alias command is active till the session is active. if you want it to be permanent declare it in user profile file (.profile  or bash profile)


It is not like you can only navigate in directory using alias, you can almost use it in all the repetitive work. For example, you want to count number of line in a file.

alias cnt='wc -l'

$ cnt F_Input_File

It will return you the number of line available in F_Input_File

alias clr='clear'

now by only typing c your screen will be cleared.

If you want to remove alias, use unalias command to remove the same.

unalias clr

will remove the alias clr.


Conclusion: You can create alias for almost all the day to day activity so utilize this feature to make your life ease....!!!

Keep Reading, Keep Learning, Keep Sharing...!!

No comments:

Post a Comment

Related Posts Plugin for WordPress, Blogger...