unable to cd when using sudo

Asked by atomic17 on 2007-02-12

base function cd "change dir" seems to be missing. When I do sudo cd

$ sudo cd config
Password:
sudo: cd: command not found

strange that I can not cd to a dir using sudo.

Question information

Language:
English Edit question
Status:
Answered
For:
Ubuntu Edit question
Assignee:
No assignee Edit question
Last query:
2007-02-12
Last reply:
2007-02-17
Bryce Harrington (bryce) said : #1

Actually cd is not a program, but a built-in for the bash shell. So you don't really 'run' it in sudo like that.

Instead, try doing this:

$ sudo bash
# cd
# [other commands...]
# exit
$

Hope this helps.

tokj (tokj-deactivatedaccount) said : #2

It is normal. There is no need to be superuser for using cd, so cd is not recognized as a command to be used with sudo. ;)

Gabriel PatiƱo (gepatino) said : #3

The cd command is a bash internal command, if you want an interactive root session, try using 'sudo -i'

After that, you will be working as root (be carefull). To leave the root session, type exit, or ctrl+d

tokj (tokj-deactivatedaccount) said : #4

It would be nice if you mark this problem as "solved" if you haven't any other problems or questions.

Best regards

Paddy Landau (paddy-landau) said : #5

@tokj: There are some situations where you cannot cd to a folder because of security permissions. In those cases, you do need either "sudo su" or "sudo -i".

Can you help with this problem?

Provide an answer of your own, or ask atomic17 for more information if necessary.

To post a message you must log in.