Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm noticing a strange issue where I appear to be forcefully cd'ed out of my MySQL data directory every time I cd to it. I'm using on OS X 10.6.1.

joebmaclap:mysql joeb$ cd /usr/local/mysql

joebmaclap:mysql joeb$ sudo cd data

joebmaclap:mysql joeb$ pwd

Notice that I am cd'ing to the data directory, but at the end of the operation, I am back in the mysql directory. I have never seen anything like this before, and I can't tell if it's a bash or MySQL issue. Does anyone know what is happening?

share|improve this question
up vote 4 down vote accepted

This is because you're using sudo, which the entire purpose of sudo is to execute one command. Once the sudo cd command exits, you are returned to the directory where you were when you executed the command.

If you need to stay in that directory, then assume a root shell, or simple execute the commands you need with sudo relative to the directory.

sudo su -
# or
sudo data/foo

(where foo is some program in data).

share|improve this answer
and sudo -i ? – juanpablo Jul 31 '11 at 20:02
Sure, sudo -i is usable. That falls under "assume a root shell". – jtimberman Aug 2 '11 at 4:04

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.