[sudo-users] Sudo and cd

Todd C. Miller Todd.Miller at courtesan.com
Mon Dec 15 07:19:18 EST 2008


In message <e8401e700812150325v105a8432u4771cbbd0ef09152 at mail.gmail.com>
	so spake "Valdemir Santos" (valdemirs):

> Why I cannot use the command "cd" with Sudo ?

>From the troubleshooting guide:

Q) When I try to use "cd" with sudo it says "cd: command not found".
A) "cd" is a shell built-in command, you can't run it as a command
   since a child process (sudo) cannot affect the current working
   directory of the parent (your shell).

Q) When I try to use "cd" with sudo the command completes without
   errors but nothing happens.
A) Even though "cd" is a shell built-in command, some operating systems
   include a /usr/bin/cd command for some reason.  A standalone
   "cd" command is totally useless since a child process (cd) cannot
   affect the current working directory of the parent (your shell).
   Thus, "sudo cd /foo" will start a child process, change the
   directory and immediately exit without doing anything useful.



More information about the sudo-users mailing list