unable to cd when using sudo

Asked by atomic17

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

$ sudo cd config
sudo: cd: command not found

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

Question information

English Edit question
Ubuntu Edit question
No assignee Edit question
Last query:
Last reply:
Revision history for this message
Bryce Harrington (bryce) said :

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.

Revision history for this message
tokj (tokj-deactivatedaccount) said :

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. ;)

Revision history for this message
Gabriel Patiño (gepatino) said :

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

Revision history for this message
tokj (tokj-deactivatedaccount) said :

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

Best regards

Revision history for this message
Paddy Landau (paddy-landau) said :

@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.