Home

sudo cd

$sudo cd /root
sudo: cd: command not found

Now what? You have to get to those config files that belong to root but you’re not root and cd doesn’t exist. cd doesn’t exist?! BUT IT DOES EXIST! WHAT?!

The Why and the Fix

Sudo is used for running independent binaries as root temporarily, while cd is not an independent program. You can try searching for cd (i.e. "whereis cd"), but it doesn’t exist! That’s because cd is part of the shell and is itself not an independent program. In order to use cd as root, we must use the shell as root. A solution is to su the way through and become the root user.

$sudo su
$cd /root

or explicitly use the shell as root temporarily

$sudo bash
$cd /root

Notes

Written on the 4th of January in 2014

Last modified on the 28th of November in 2015