Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I added a directory path to system path($PATH) by running,

export PATH=$PATH:/home/avinash/Desktop/raj

Now my path look like this,

$ echo $PATH

I want to remove /home/avinash/Desktop/raj from system path variable by using command(like export command does on adding path).

share|improve this question
where did you put the export statement? – souravc Mar 12 '14 at 17:50
gnome terminal(ctrl+alt+t) – Avinash Raj Mar 12 '14 at 17:52
up vote 4 down vote accepted

Running export PATH=$PATH:/... doesn't set your PATH system-wide. It's just a shell variable. Start a new shell and BOOM, it's gone. Obviously if you've added that to ~/.bashrc (or another environment bootstrap file) you'll have to revert that change but it doesn't sound like your problem here.

If you're desperate not to start a new shell, you could set it by removing it manually, with:

export PATH=/usr/lib/lightdm/lightdm:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games
share|improve this answer

In your current shell (your current session of gnome-terminal) you can do this using:

export PATH=${PATH%:/home/avinash/Desktop/raj}

In general:


deletes shortest match of $substring from back of $string.

Check out String manipulation for more info.

share|improve this answer

If you put the export statement in any shell initiation file like ~/.bashrc, you can use the following commands in terminal,

#remove the export statement from the file.
sed -i 's#export PATH=$PATH:/home/avinash/Desktop/raj##g' ~/.bashrc
#source ~/.bashrc
. ~/.bashrc

It will remove the folder from path.

If you have exported the path from a terminal

The folder will be in path as long as you are in that shell. To overwrite the path you have to assign new path. As oli already mentioned in the other answer.

You can use the following command to set old path

export PATH=`echo ${PATH/\:\/home\/avinash\/Desktop\/raj/}`

Or, simply

export PATH=${PATH/':/home/avinash/Desktop/raj'/}

This is Substring Replacement,

share|improve this answer

If you want use it as a command, here is a little script:


# This script removes folder from PATH variable
# Folders to remove reading as arguments

if [ $# -lt 1 ]; then
    echo "You should give at least one argument"
    echo "For example"
    echo "$0 /usr/local/bin"
    FOLDERS_TO_REMOVE=`echo $@ | sed 's/ /|/g'`

    echo "You actually PATH variable is:"
    echo $PATH
    echo "###"

    PATH=$( echo ${PATH} | tr -s ":" "\n" | grep -vwE "(${FOLDERS_TO_REMOVE})" | tr -s "\n" ":" | sed "s/:$//" )

    echo "Now you need to run"
    echo "export PATH=$PATH"

Name it unexport, and add it to your PATH.


unexport /usr/local/bin /bin /sbin

This script does not change your actually PATH. If you want script to do it, you should change last line. Substitute echo "export PATH=$PATH" to export PATH=$PATH

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.