LinuxQuestions.org

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

stf92 01-06-2011 08: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 09: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 10:26 AM

Try:
Code:

sudo -i
cd  /
cd  /root
ls
exit


siranjeevi 01-06-2011 11:51 AM

Not sure about Slackware but for Ubuntu you can use

sudo su
cd /root

prh47 03-03-2012 09: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 06:17 PM.