Page 1 of 1

[SOLVED] Command 'ifconfig' is available in '/sbin/ifconfig'

Posted: Wed Nov 30, 2011 3:03 am
by WhatUsernameIsFree?
Hi, when I try type ifconfig I get:

Code: Select all

Command 'ifconfig' is available in '/sbin/ifconfig'
The command could not be located because '/sbin' is not included in the PATH environment variable.
This is most likely caused by the lack of administrative priviledges associated with your user account.
ifconfig: command not found
Apparently the solution is related to adding /sbin/ to my echo $PATH which shows

Code: Select all

/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games

I cannot 'nano $PATH', so how can I edit my $PATH?

Thank you :)

Re: LMDE: Command 'ifconfig' is available in '/sbin/ifconfig

Posted: Wed Nov 30, 2011 11:39 am
by Oscar799
Moved here from the main forum

Re: LMDE: Command 'ifconfig' is available in '/sbin/ifconfig

Posted: Wed Nov 30, 2011 12:41 pm
by doktordave
WhatUsernameIsFree?,

Try this instead:

Code: Select all

sudo ifconfig

Re: LMDE: Command 'ifconfig' is available in '/sbin/ifconfig

Posted: Wed Nov 30, 2011 2:38 pm
by WhatUsernameIsFree?
Thanks for moving to a more appropriate section. :)

sudo ifconfig works, is that expected behaviour? I ask as typing in '/sbin/ifconfig' works too. Surely if it was expected behaviour I should get an error relating to needing sudo when I type 'ifconfig'

I've exactly the same problem with 'powertop', but that *does* require sudo and displays this message if I type /usr/sbin/powertop

Code: Select all

PowerTOP 1.97 beta 1 must be run with root privileges.
exiting...
Thanks

Re: LMDE: Command 'ifconfig' is available in '/sbin/ifconfig

Posted: Wed Nov 30, 2011 3:17 pm
by Anakinholland
WhatUsernameIsFree? wrote:sudo ifconfig works, is that expected behaviour? I ask as typing in '/sbin/ifconfig' works too. Surely if it was expected behaviour I should get an error relating to needing sudo when I type 'ifconfig'
Hya, 2 different things mate, one requires root to run, other doesn't know where to find the executable.

$PATH is a shell-variable, not a file, so an editor is useless as you already noticed :) It is filled when you log on to the system, and you can change it like this:

Code: Select all

vi ~/.profile
or

Code: Select all

gedit ~/.profile
~/ is short-hand for your home-directory. If you view your home-directory you will most likely not see it immediately, as the . (period) in front of the file makes it hidden. It will show up using "ls" if you add the parameter "-a", or in your filebrowser when you press Ctrl+H (assuming it is Nautilus).

Anyway, in the last part of the file you will see something like this bit:

Code: Select all

# set PATH so it includes user's private bin if it exists
if [ -d "$HOME/bin" ] ; then
    PATH="$HOME/bin:$PATH"
fi
Change

Code: Select all

PATH="$HOME/bin:$PATH"
to

Code: Select all

PATH="$HOME/bin:/sbin:$PATH"
Then log out and back in.

The reason why this does work for sudo is most likely that user root does have /sbin in $PATH, but my test doesn't quite prove that.

If I run the next commands i may become clear:

Code: Select all

anakin@stormbird ~ $ echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games
anakin@stormbird ~ $ PATH=$PATH:/test
anakin@stormbird ~ $ echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/test
anakin@stormbird ~ $ sudo echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/test
anakin@stormbird ~ $ sudo su -
stormbird ~ # echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
Personally I didn't expect to be any difference between sudo and actually being root. As you can see, a regular "echo" and "sudo echo" have identical output, but clearly on your system it would not, else ifconfig would have worked for you!?

Maybe someone else can explain that, at least you'll have a work-around for now :)

Regards,

Anakin

Re: LMDE: Command 'ifconfig' is available in '/sbin/ifconfig

Posted: Fri Dec 02, 2011 6:34 pm
by WhatUsernameIsFree?
Thanks for you help.

Would be interested to hear the answer as to why sudo echo $PATH and echo $PATH as root come up with different things. :)

Re: LMDE: Command 'ifconfig' is available in '/sbin/ifconfig

Posted: Sat Dec 03, 2011 5:32 pm
by xircon
Because different users can have different paths. Sudo elevates the command to use root privileges, whilst staying as the same user.

Proof:

Code: Select all

sudo echo $PATH
/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games:/usr/sbin <<<< USER
molly2@n5010 ~ $ 
molly2@n5010 ~ $ echo $PATH
/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games:/usr/sbin <<<< USER
molly2@n5010 ~ $ su
Password: 
n5010 molly2 # echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin <<<< ROOT
n5010 molly2 # 

Re: LMDE: Command 'ifconfig' is available in '/sbin/ifconfig

Posted: Sun Dec 04, 2011 4:35 am
by WhatUsernameIsFree?
xircon wrote:Because different users can have different paths. Sudo elevates the command to use root privileges, whilst staying as the same user.
Hi,

Thanks, for me that certainly explains the differences, as well as the difference between suing to root and sudo :)

Love this forum, when you ask 'silly' questions you're not treated like an idiot! :)

Re: LMDE: Command 'ifconfig' is available in '/sbin/ifconfig

Posted: Sun Dec 04, 2011 4:53 am
by xircon
I know, nice people with a helpful attitude & good sense of humour, I came from Mandriva and knew sod all about apt, so had lots of basic questions. Can't even remember simple urpmi commands now :)

Re: [SOLVED] Command 'ifconfig' is available in '/sbin/ifcon

Posted: Fri Feb 17, 2012 12:46 am
by nukeqler
The reason that

Code: Select all

sudo echo $PATH
is the same as

Code: Select all

echo $PATH
is that in both cases the shell expands the variable before running the command line, so the actual arguments that sudo gets are 'echo /bin:/usr/sbin'.