web123456

Why can't sudo cd be executed

Problem description

I wantcdarrive/etc/docker, but it gives me oneInsufficient permissionsThe error, then, I thought of usingsudo cd /etc/dockerWhen it told mesudo: cd: command not found

So, I was so depressed that I went online to find out the reason.

Problem analysis

cdNot an application but a built-in command in Linux,sudoJust work for the application.

sudo fooIt only means running the foo program with root permissions

so,sudo cd /etc/dockerReportsudo: cd: command not found

verify

> type cd
cd is a shell builtin

Note that regarding whether cd is a built-in command, cd is not a built-in command in OS X 10.8 (refer towhat-is-the-point-of-the-cd-external-command), I don't know the specific version of OS X. Most Linux series (Ubuntu, CentOS and ArchLinux) have built-in commands

Solution

  • usesudo -iCommand to increase user permissions
> sudo -i
> cd /etc/docker
  • usesudo -sCommand to open a special shell
> sudo -s
> cd /etc/docker

All above can use the exit command to exit, or use the Ctrl+D shortcut key to exit

Reference article

  • why-doesnt-sudo-cd-var-named-work
  • how-can-i-cd-into-a-directory-as-root
  • what-is-the-point-of-the-cd-external-command