Let's say there's a directory that I don't have the privileges to access. Obviously sudo cd foo won't work, because cd is a shell builtin in every shell ever.So far, I've just been using sudo bash (yes I know there are better ways) to get a root prompt. Then, I can cd into the directory to poke around.Is there a better way to do this?
How can I cd into a directory as root?
bash;sudo;cd command
Nope, there isn't a way to cd to a directory that only allows root without being root. There really shouldn't be too many directories that have this limitation. Most of the time it's the access to a given file that's limited such as the /etc/shadow file or specific log files under /var/log.You can use sudo ls <dir> to see them instead of bash. Also when using sudo to become root you typically want to set user (su command) instead of bash, so use this command instead:$ sudo su -You can also accomplish the same thing with a sudo's -i switch:$ sudo -iexcerpt from man page regarding sudo -iThe -i (simulate initial login) option runs the shell specified in the  passwd(5) entry of the target user as a login shell.  This means that  login-specific resource files such as .profile or .login will be read  by the shell.  If a command is specified, it is passed to the shell  for execution.  Otherwise, an interactive shell is executed.For the files that you can't access you can use either of these sudo commands:$ sudo tail /var/log/messages$ sudo less /etc/shadow