Learn basics of Linux hacking for hacking aspirants Part 9 – Environment Variables in Linux Command Line

What is Linux Environment – Set environment variable Linux

In this article we are going to talk about the environment variable. In windows, there is same concept of environment variables, but nobody keeps an eye on it. If you are working on Linux then you have to work with the Linux environment variables. I am going to tell you all the things I know about Linux environment variables.

Linux Environment Variables Command Line

Environment variables are those variables that are available to all the users. There are some environment variables for every user whether it is a root user or a normal user. There are some default values that are assigned to these variables. If we use these variables then we can improve our performance & user experience in the System.

View Linux environment variables – Linux Environment Variables file

To view our environment variables, we can easily check by using the set command.

set

This command will show all the environment variables, user defined functions & other aliases. The name of environment variables are in uppercase like   HOME, PATH, HISTSIZE, etc. To check the value of any environment variable type

echo $PATH

we have to use $ sign to use a variable in Linux.
The variable PATH is used to store all the drive path that are used in the current session. If we want to clear all the values form the variable PATH, then we need to do this.

PATH =0

Also Read : Learn basics of Linux hacking for hacking aspirants Part 7

After we will close the terminal, the value of the variable that we just changed will be set to the default value. You can choose to set the value after the closing of your terminal. The command used for this is given below. Basically the command will export the value of environment variables to the next terminal.

export PATH

Change the name of terminal

This can be a fun activity. In this we are going to change the name of terminal from kali to “Best hacker”. Type this the prompt

PS1= “Best Hacker: #”

This will change the prompt name, but when you will exit the prompt, the name will changed back to kali. To change the name for ever, so that as many times I open the prompt, the name is same as Best hacker.  To do this type

export PS1

Changing Our PATH variable

PATH is a very important variable of Linux. When we type a command then the kernel searches it in the PATH variable . It the command is not found then the message shows “Command not found”.

echo =$PATH

As PATH contains many sub-directories in it. When we type any command & try to execute it, the command is first checked in the PATH directory or its sub-directory for the command definition.

linux environment variables
linux environment variables

We are going to use the command to execute an application in such a way that we can use it anytime without specifying the actual path of that application. For example we want to use aircrack-ng.

PATH=$PATH:/pentest/wireless/aircrack-ng

After this command will be executed by the terminal, the application aircrack-ng can be used anywhere by just typing the name.
Be careful about using this command, you should not add too many names in the PATH variable. If you will do this, the performance of your terminal will be slow down.
Also Read : Learn basics of Linux hacking for hacking aspirants Part 8
Done for the day. The information about Linux environment variable is complete. If you like the article please tell me in the comment box. Thank you.

Leave a Comment