LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 09-14-2006, 11:48 AM   #1
infraredgirl
Member
 
Registered: Feb 2006
Location: Belgrade, Serbia
Distribution: Slackware 11.0
Posts: 40

Rep: Reputation: 15
How to remove directory from $PATH


I accidentally added a wrong directory to $PATH. How do I remove it?
 
Old 09-14-2006, 12:03 PM   #2
olaola
Member
 
Registered: Aug 2006
Location: Italy
Distribution: Fedora
Posts: 41

Rep: Reputation: 15
How did you added the directory?
 
Old 09-14-2006, 12:06 PM   #3
infraredgirl
Member
 
Registered: Feb 2006
Location: Belgrade, Serbia
Distribution: Slackware 11.0
Posts: 40

Original Poster
Rep: Reputation: 15
Like this:
Code:
export PATH=${PATH}:/blah/wrongdir
 
Old 09-14-2006, 12:16 PM   #4
olaola
Member
 
Registered: Aug 2006
Location: Italy
Distribution: Fedora
Posts: 41

Rep: Reputation: 15
if you reboot your machine (or maybe simply logout) the PATH will be read from the ~/.bash_profile file, so restored as previously
 
Old 09-14-2006, 06:01 PM   #5
infraredgirl
Member
 
Registered: Feb 2006
Location: Belgrade, Serbia
Distribution: Slackware 11.0
Posts: 40

Original Poster
Rep: Reputation: 15
Yes you are right.
Thank you.
 
Old 09-14-2006, 10:36 PM   #6
ntubski
Senior Member
 
Registered: Nov 2005
Distribution: Arch
Posts: 3,013

Rep: Reputation: 1225Reputation: 1225Reputation: 1225Reputation: 1225Reputation: 1225Reputation: 1225Reputation: 1225Reputation: 1225Reputation: 1225
Next time you can set PATH to the empty string then rerun /etc/profile and ~/.bash_profile like this:
Code:
PATH=""
source /etc/profile
source ~/.bash_profile
No reboot/logout necessary

Edit: I thought of a better way
Code:
PATH=$(echo $PATH |sed 's/\/blah\/wrongdir//')

Last edited by ntubski; 09-15-2006 at 08:06 AM.
 
1 members found this post helpful.
Old 03-27-2009, 06:31 AM   #7
Paris Heng
Member
 
Registered: Jul 2007
Location: Kuala Lumpur, Malaysia
Distribution: Ubuntu 8.04, Solaris 10
Posts: 198

Rep: Reputation: 30
Quote:
Originally Posted by olaola View Post
if you reboot your machine (or maybe simply logout) the PATH will be read from the ~/.bash_profile file, so restored as previously
I also having the problems today, why the alteration never permanently store in the kernel? I wonder, export PATH=${PATH}:/blah/wrongdir, never store permanently?
 
Old 03-27-2009, 06:52 AM   #8
i92guboj
Gentoo support team
 
Registered: May 2008
Location: Lucena, Córdoba (Spain)
Distribution: Gentoo
Posts: 4,063

Rep: Reputation: 381Reputation: 381Reputation: 381Reputation: 381
Quote:
Originally Posted by Paris Heng View Post
I also having the problems today, why the alteration never permanently store in the kernel? I wonder, export PATH=${PATH}:/blah/wrongdir, never store permanently?
I don't know what do you mean but environment variables have nothing to do with the kernel, not even with linux. They are parsed by the shell and have meaning only while you are inside a shell.

~/.bashrc and ~/.bash_profile just happen to be two of the the initialization files for bash, which is just one of the available shells. If you were using tcsh, zsh or ksh then they would be different.

It's the way that shells work, if you want something to be permanent you have to put it on their initialization files, bash doesn't save anything automatically, and I can't think of any other shell that does so.

About "export", well, it doesn't export anything in that sense that you probably though. "export" is just a keyword that tells bash that that variable should be marked as exportable, so it will be available for child processes in case they need it. If the variable is not exported, most child processes will not be able to see a variable that you set in the current shell. It doesn't save anything and it doesn't "export" anything to the config files either, if that's what you thought.

Last edited by i92guboj; 03-27-2009 at 07:10 AM.
 
Old 03-27-2009, 06:53 AM   #9
vlademir
Member
 
Registered: Jan 2009
Location: The Netherlands
Distribution: Centos,Ubuntu,Mandriva,Suse11.1
Posts: 86

Rep: Reputation: 17
To remove that directory without rewriting the whole PATH, if i remember this will be the command :

Quote:
export PATH=`echo $PATH | sed -e 's/:\/blah\/wrongdi$//'`
Hope will help
 
Old 03-27-2009, 07:17 AM   #10
i92guboj
Gentoo support team
 
Registered: May 2008
Location: Lucena, Córdoba (Spain)
Distribution: Gentoo
Posts: 4,063

Rep: Reputation: 381Reputation: 381Reputation: 381Reputation: 381
In bash a builtin can take care of that as well:

Code:
PATH="${PATH/\/path\/to\/remove/}"
 
Old 03-27-2009, 09:24 AM   #11
Paris Heng
Member
 
Registered: Jul 2007
Location: Kuala Lumpur, Malaysia
Distribution: Ubuntu 8.04, Solaris 10
Posts: 198

Rep: Reputation: 30
Quote:
Originally Posted by i92guboj View Post
I don't know what do you mean but environment variables have nothing to do with the kernel, not even with linux. They are parsed by the shell and have meaning only while you are inside a shell.

~/.bashrc and ~/.bash_profile just happen to be two of the the initialization files for bash, which is just one of the available shells. If you were using tcsh, zsh or ksh then they would be different.

It's the way that shells work, if you want something to be permanent you have to put it on their initialization files, bash doesn't save anything automatically, and I can't think of any other shell that does so.

About "export", well, it doesn't export anything in that sense that you probably though. "export" is just a keyword that tells bash that that variable should be marked as exportable, so it will be available for child processes in case they need it. If the variable is not exported, most child processes will not be able to see a variable that you set in the current shell. It doesn't save anything and it doesn't "export" anything to the config files either, if that's what you thought.
Sorry make you misunderstanding. What I want to ask is, did the "export" write anything into the config files in the FS?
 
Old 03-27-2009, 09:43 AM   #12
i92guboj
Gentoo support team
 
Registered: May 2008
Location: Lucena, Córdoba (Spain)
Distribution: Gentoo
Posts: 4,063

Rep: Reputation: 381Reputation: 381Reputation: 381Reputation: 381
Quote:
Originally Posted by Paris Heng View Post
Sorry make you misunderstanding. What I want to ask is, did the "export" write anything into the config files in the FS?
That's what I guessed

Then, as I explained in the previous post, the answer is "no". Export just marks the variable to be kind of "inherited" by child processes.
 
Old 03-18-2011, 01:50 PM   #13
emaborsa
LQ Newbie
 
Registered: Mar 2011
Posts: 1

Rep: Reputation: 0
Quote:
Originally Posted by i92guboj View Post
That's what I guessed

Then, as I explained in the previous post, the answer is "no". Export just marks the variable to be kind of "inherited" by child processes.
What have i to do to do the changes of the path permanently? Do i have to change the .bash_profile or bashrc? if Yes, how?
 
Old 03-19-2011, 04:22 AM   #14
i92guboj
Gentoo support team
 
Registered: May 2008
Location: Lucena, Córdoba (Spain)
Distribution: Gentoo
Posts: 4,063

Rep: Reputation: 381Reputation: 381Reputation: 381Reputation: 381
Quote:
Originally Posted by emaborsa View Post
What have i to do to do the changes of the path permanently? Do i have to change the .bash_profile or bashrc? if Yes, how?
Code:
PATH="$PATH:/new/path"
# or
PATH="/new/path:$PATH"
Depending on whether you want your new path to appear before of after when searching for binaries.

The concrete file(s) where you should put this depends on which do you want. It's all explained in the bash man page, but, if you use bash just in terminal emulators (like konsole, gnome-terminal, xterm, etc.) then ~/.bashrc is probably your file.

http://www.gnu.org/software/bash/man...-Startup-Files
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
rm: cannot remove directory `ff': Directory not empty blancs Linux - General 17 08-29-2011 02:47 PM
how do I remove a variable from PATH melinda_sayang Slackware 17 02-28-2009 01:55 PM
How to rsynce the actual directory path instead of just the directory at the end of Niceman2005 Linux - General 5 04-08-2005 08:58 PM
remove directory from a users PATH reddazz Linux - General 4 01-14-2005 11:29 AM
how to remove PATH variable? greg108 Linux - Newbie 2 08-22-2003 02:55 PM


All times are GMT -5. The time now is 01:45 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration