Can't do: sudo cd /var/cron/tabs

Rick Barter rvb01 at
Wed Jul 16 19:08:54 EDT 2003

On Wed, Jul 16, 2003 at 06:02:55PM -0500, donald.ritchey at wrote:
> 'cd' is a shell built-in.  It changes the operating environment of the
> current shell.  To do what you want to do, you need to be able to run a
> command pipeline through sudo.  For example, to see the content of 'tabs',
> you would run:
> 	sudo sh -c 'cd tabs; ll';
> To copy any text files in tabs to your home directory, you would run:
> 	sudo sh -c "cd tabs; cp *.txt ${HOME}/"
> Even if you could do the 'cd' within sudo, here is what would happen:
> 	you run: sudo cd tabs
> 	sudo starts a new shell with the command 'cd' changing directory to
> 'tabs' within that shell.
> 	The new shell changes to /var/cron/tabs as its current working
> directory
> 	No other commands are found for the shell to execute, so it exits.
> 	You are back in your original starting point of /var/cron.
> Is this a clear explanation of why you can't use sudo to simply change
> directory into a new directory, without giving the new shell something else
> to do?
Absolutely!  Thanks, Don.  I appreciate it greatly.  Thanks for also
showing me how I can accomplish my task.  AWESOME!

Thanks again,


More information about the sudo-users mailing list