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
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:
Last reply:
Revision history for this message
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.

Revision history for this message
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. ;)

Revision history for this message
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

Revision history for this message
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

Revision history for this message
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.