LinuxQuestions.org
Help answer threads with 0 replies.
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 05-21-2008, 05:24 AM   #1
kaiwan
Member
 
Registered: Sep 2006
Posts: 52

Rep: Reputation: 15
editing PATH in bash profile


Hi!
I have installed Fedora 9.
When I try to run some command, like fdisk I get following error:
Code:
[miroslav@localhost ~]$ fdisk
bash: fdisk: command not found
[miroslav@localhost ~]$ sudo fdisk
sudo: fdisk: command not found
So I edited my bash profile to add /sbin and /usr/sbin to PATH,
and it looks lite this now:
Code:
# .bash_profile

# Get the aliases and functions
if [ -f ~/.bashrc ]; then
	. ~/.bashrc
fi

# User specific environment and startup programs

PATH=$PATH:/usr/sbin:/sbin:$HOME/bin

export PATH
unset USERNAME
And still I cant run fdisk, only way to run it is like this:
Code:
sudo /sbin/fdisk
Does not work after log out or reboot.

Last edited by kaiwan; 05-21-2008 at 05:26 AM.
 
Old 05-21-2008, 05:43 AM   #2
Nathanael
Member
 
Registered: May 2004
Location: Karlsruhe, Germany
Distribution: debian, gentoo, os x (darwin), ubuntu
Posts: 940

Rep: Reputation: 33
what does
Code:
sudo -s
echo $PATH
give you?

note: sudo echo $PATH is not the same!

Last edited by Nathanael; 05-21-2008 at 05:45 AM.
 
Old 05-21-2008, 05:54 AM   #3
kaiwan
Member
 
Registered: Sep 2006
Posts: 52

Original Poster
Rep: Reputation: 15
Quote:
Originally Posted by Nathanael View Post
what does
Code:
sudo -s
echo $PATH
give you?

note: sudo echo $PATH is not the same!
Gives me this:

While not root:
Code:
[miroslav@localhost ~]$ echo $PATH
/usr/kerberos/bin:/usr/local/bin:/usr/bin:/bin:/home/miroslav/bin
[miroslav@localhost ~]$
Root - with sudo:

Code:
[miroslav@localhost ~]$ sudo -s
[sudo] password for miroslav: 
[root@localhost ~]# echo $PATH
/usr/kerberos/sbin:/usr/kerberos/bin:/usr/bin:/bin
[root@localhost ~]#
Root - with su:
Code:
[miroslav@localhost ~]$ su
Password: 
[root@localhost miroslav]# echo $PATH
/usr/kerberos/sbin:/usr/kerberos/bin:/usr/local/bin:/usr/bin:/bin:/home/miroslav/bin
[root@localhost miroslav]#
 
Old 05-21-2008, 05:58 AM   #4
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976
You cannot run fdisk without being root. Actually you can, but it does nothing nor spit any error message. I think it checks if your UID is 0 (root) otherwise exits.
 
Old 05-21-2008, 06:02 AM   #5
kaiwan
Member
 
Registered: Sep 2006
Posts: 52

Original Poster
Rep: Reputation: 15
Quote:
Originally Posted by colucix View Post
You cannot run fdisk without being root. Actually you can, but it does nothing nor spit any error message. I think it checks if your UID is 0 (root) otherwise exits.
Problem exist wile I am root as well:

Code:
[miroslav@localhost ~]$ su
Password: 
[root@localhost miroslav]# fdisk
bash: fdisk: command not found
 
Old 05-21-2008, 06:25 AM   #6
jschiwal
LQ Guru
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 670Reputation: 670Reputation: 670Reputation: 670Reputation: 670Reputation: 670
You need to run "su -" to run as root with root's environment. What is wrong with "sudo /sbin/fdisk"?

Also, .profile or .bash_login are better places to edit your PATH variable. Every subshell you launch will add /usr to path again unless you test for it's presence before adding it.
 
Old 05-21-2008, 06:44 AM   #7
kaiwan
Member
 
Registered: Sep 2006
Posts: 52

Original Poster
Rep: Reputation: 15
Quote:
Originally Posted by jschiwal View Post
You need to run "su -" to run as root with root's environment. What is wrong with "sudo /sbin/fdisk"?
Thanks, that worked:
Code:
[miroslav@localhost ~]$ su -
Password: 
[root@localhost ~]# fdisk

Usage: fdisk [-l] [-b SSZ] [-u] device
E.g.: fdisk /dev/hda  (for the first IDE disk)
  or: fdisk /dev/sdc  (for the third SCSI disk)
  or: fdisk /dev/eda  (for the first PS/2 ESDI drive)
  or: fdisk /dev/rd/c0d0  or: fdisk /dev/ida/c0d0  (for RAID devices)
  ...
[root@localhost ~]# echo $PATH
/usr/kerberos/sbin:/usr/kerberos/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/usr/sbin:/sbin:/root/bin
Nothing is wrong with "sudo /sbin/fdisk",
but I wanted to explore other options.

Quote:
Originally Posted by jschiwal View Post
Also, .profile or .bash_login are better places to edit your PATH variable. Every subshell you launch will add /usr to path again unless you test for it's presence before adding it.
Not sure I understand what to do ?

Last edited by kaiwan; 05-21-2008 at 06:48 AM.
 
Old 05-21-2008, 07:07 AM   #8
jschiwal
LQ Guru
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 670Reputation: 670Reputation: 670Reputation: 670Reputation: 670Reputation: 670
If you don't have a ~/.profile or ~/.bash_login file you can create one yourself and put the same "export PATH=PATH:/usr" command there instead of in ~/.bashrc.

When you login, your .profile might source your .bash_rc file. When you open a new terminal, such as konsole, ~/.bashrc will be run again, and your PATH variable will end with ":/usr:/usr". Some PATH variables contain many more paths, for example adding directories for KDE, Gnome & Java. Having them repeated two or three times in PATH may waste some time searching in the same directories more than once.
 
Old 05-21-2008, 07:15 AM   #9
kaiwan
Member
 
Registered: Sep 2006
Posts: 52

Original Poster
Rep: Reputation: 15
Quote:
Originally Posted by jschiwal View Post
If you don't have a ~/.profile or ~/.bash_login file you can create one yourself and put the same "export PATH=PATH:/usr" command there instead of in ~/.bashrc.

When you login, your .profile might source your .bash_rc file. When you open a new terminal, such as konsole, ~/.bashrc will be run again, and your PATH variable will end with ":/usr:/usr". Some PATH variables contain many more paths, for example adding directories for KDE, Gnome & Java. Having them repeated two or three times in PATH may waste some time searching in the same directories more than once.
thanks, I will try to do that!
 
Old 05-21-2008, 07:40 AM   #10
Nathanael
Member
 
Registered: May 2004
Location: Karlsruhe, Germany
Distribution: debian, gentoo, os x (darwin), ubuntu
Posts: 940

Rep: Reputation: 33
would it search more than once? i thought when a file is searchd in $PATH it stops after the first match...
 
Old 05-21-2008, 08:14 PM   #11
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.8, Centos 5.10
Posts: 17,258

Rep: Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328
Y, but if it doesn't find it, it'll continue to search every dir in the PATH, each time it appears...!
 
  


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
Do you add to the path line or make a new path in /etc/profile? M$ISBS Linux - Newbie 2 12-13-2006 03:14 PM
It's about editing 'etc/profile' bicbac Linux - Newbie 5 08-30-2005 10:06 PM
editing profile.. andox LQ Suggestions & Feedback 2 07-05-2003 07:50 PM
Editing path permanently...but I don't have .bashrc or .profile shock_ez Linux - Newbie 6 07-02-2003 06:16 PM
About Editing the User Profile emmanuelmathew LQ Suggestions & Feedback 2 02-06-2003 04:48 PM


All times are GMT -5. The time now is 07:46 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