Why does sudo not work with the cd command?

Updated -

The cd command is built into the default GNU Bourne-Again SHell (bash) shell and will not work with sudo since the current directory is a attribute of a process. Any operations performed by sudo and its descendants will not affect the parent process.

The workaround is to call the cd command within an independent shell:

$...

Subscriber exclusive content

A Red Hat subscription provides unlimited access to our knowledgebase, tools, and much more.

Current Customers and Partners

Log in for full access

Log In

New to Red Hat?

Learn more about Red Hat subscriptions

Using a Red Hat product through a public cloud?

How to access this content