Linux security

Easier way to add DIRECTORY to your path in LINUX

$PATH is very important environment variable and knowing how to work with it, can be very useful

What Is $PATH on Linux, and How Does It Work?

Every time you run a command, it is the $PATH environment variable which is being used to determine where to look for command. One common location is the /bin directory. It’s a directory that contains some of the most commonly used commands such as pwd, ls, cp, mkdir, touch, dd, df, du, tail, less, more, and etc.

You can display your $PATH using the echo command. Here’s the command.

echo $PATH

$PATH variable is very useful because it allows the command to be executed without knowing or specifying the full path to the command.

You should note that every single entry into PATH is separated by (:) semicolon sign.

Adding a Directory to Your $PATH

Example I want to add my SCRIPTS directory into $PATH

  • Do cd ~/SCRIPTS and run pwd
  • You should be see the full path of your Directory┬á /home/ME/SCRIPTS

There are two ways do it — little work and another quick command ­čÖé


  • Once you got the output from pwd and know the full path
  • open your editor and edit ~/.bashrc file
  • nano ~/.bashrc
  • Scroll down in the file
  • Type at the end of file this line
export PATH="/home/ME/SCRIPTS:$PATH
  • CTRL+XYES to save the file
  • you can also run source ~/.bashrc
  • Verify now the $PATH by running echo
echo $PATH

And now you should see the Directory included in your $PATH

Option #2

This second option is much simpler and fast

  • Go inside of the directory /home/ME/SCRIPTS
  • Run this command

echo “export PATH=$(pwd):\${PATH}”┬á >> ~/.bashrc

source ~/.bashrc
echo $PATH
  • This command will add to your path the Directory in which you at right now,
  • refresh and reload the ~/.bashrc
  • output the $PATH so you can verify that the directory has been added into your $PATH.


Leave a Reply