CUSTOM COMMAND FOR LINUX TERMINAL(ALIAS LINUX):COMPLETE GUIDE TO SETUP ALIAS IN LINUX

SETUP A CUSTOM ALIAS COMMAND TO OPEN A PROGRAM FROM ANYWHERE IN THE TERMINAL:KALI LINUX ALIAS TUTORIAL

Kali Linux is great. It has all the hacking tools loaded by default, it's light weight, you have control over everything and it gives you a feeling of Mr Robot. I've written an article about attacking a WiFi network in which you don't even have access to. Click Here if you are interested in it.
Typing out the commands and hearing the keystrokes can be soothing and satisfying but not always. Since most of the work we do in Kali Linux are through CUI or by typing the exact commands, it's important that you know how to type fast and accurate. You have to type every files' path in order to just open it which I think is not comfortable. Although, typing is not comfortable, but, come on, we are Kali users. We love keystrokes and we are proud of our finger speed.

Keeping proud feelings aside, sometimes it's hard to type a long path to open a program, sometimes we maybe in a hurry, sometimes we have to perform some operations fast. In this case, how easy will it be if we can just define a reserved keyword for ourselves to perform a certain task for us, to open a program we commonly and frequently use. Well. worry not. You, my brothers and sisters are going to learn about a simple trick to do that. Well, it's not a trick, it's just what you are given as an option but who cares?

So, how does it work?(For those true Linux Users who want to know everything)

There is a file in your system named ' .bashrc '. Its main purpose is to give you a space where you can set up your own custom variables containing the information about your commands. What is bash? To know more about bash refer to this Wikipedia entry HERE. You can include your own custom functions, names(aliases) that you want to use in the terminal. Every time when you open a new terminal window, it is started automatically, loading all the identifiers containing your commands. Although you can put anything as your preference inside this file, the most commonly used feature is to setup aliases or shortcut names that points or executes a command. One thing about these aliases are that they are permanently stored and started whenever you open a new terminal window or cmd window. It's similar to that in windows where you specify a environment variable that contains information about a certain program you want to use or link.

Types of Aliases:

1) Temporary Aliases

These are aliases you want for a single session. If you want a variable name to represent a function or command as long as you are using a terminal session. The variable name(identifier) and the information it contains are automatically erased when you shut your machine down. These types of aliases are defined from a terminal.

2) Permanent Aliases

These are the aliases or identifiers that are set permanently and can be used in multiple terminal windows. The identifier and the information associated with it are not erased even when the computer is shut down. These types of aliases are defined and saved in a file named '.bashrc' which is inside your system folders.

How to create an Alias with custom command in Linux:

Temporary Aliases are defined in a terminal as:


alias (name you want to give)='action you want it to perform'

For example: I want to open a program called xampp which is inside a specific directory. Initially what I have to do was to locate the position of the program file and execute. After adding the alias name I can just type the variable name and it will run like a charm:

Initially without alias addition, to open it, I have to type:
 cd /opt/lampp/xampp


Now adding alias name as:
 alias xampp='/opt/lampp/xampp'

 
After adding alias name, to open it, I can just type:
xampp  

 

Steps to create permanent Aliases

  1. Open Terminal
  2. Type mousepad .bashrc
  3. A text editor will open as follows
  4. Find lines containing #alias (codes)
  5. In between those lines type alias (name you want to give)='action you want to perform'

For example I want to create a shortcut for xampp as shown above but this time I need it permanent one. Then I'll do: 

 alias xampp='/opt/lampp/xampp'

 This code needs to be typed in .bashrc file.

If you have any queries regarding this technique or encounter any sort of problem during its setup, just comment down below. 

Have a great day, geeks.

Post a Comment

0 Comments