LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (http://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   sudo cd /root gives 'sudo: cd: command not found'. (http://www.linuxquestions.org/questions/linux-newbie-8/sudo-cd-root-gives-sudo-cd-command-not-found-854617/)

stf92 01-06-2011 09:44 AM

sudo cd /root gives 'sudo: cd: command not found'.
 
Kernel 2.6.21.5, Slackware 12.0

Hi:
Code:

# cat /etc/sudoers
root  ALL = (ALL) ALL
pete  ALL = (ALL) NOPASSWD: ALL

Code:

pete$ ls /root
permission denied
pete$ sudo ls /root
loadlin.txt loadlin.zip
pete$ cd /root
-bash: cd: /root: Permission denied
pete$ sudo cd /root
sudo: cd: command not found
pete$

On the other hand
Code:

pepe$ echo $SHELL
/usr/bin/bash
pepe$ sudo echo $SHELL
/usr/bin/bash

So, I do not understand why the notification "sudo: cd: command not found", considering cd is a bash built-in command. Any suggestion will be welcome.

AlucardZero 01-06-2011 10:01 AM

Precisely because "cd" is a shell builtin and not a binary, and sudo is not bash (nor even a shell). So sudo can't find any "cd" command. That's how it works, so you'll need to find some way around using "sudo cd", like by using complete paths in your commands or just doing "sudo bash".

tredegar 01-06-2011 11:26 AM

Try:
Code:

sudo -i
cd  /
cd  /root
ls
exit


siranjeevi 01-06-2011 12:51 PM

Not sure about Slackware but for Ubuntu you can use

sudo su
cd /root

prh47 03-03-2012 10:05 AM

Thanks
 
Thanks for the help. That did the trick for me on Linux Mint.

Quote:

Originally Posted by siranjeevi (Post 4215463)
Not sure about Slackware but for Ubuntu you can use

sudo su
cd /root



All times are GMT -5. The time now is 10:16 PM.