up vote 2 down vote favorite
share [g+] share [fb]

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 Terminal.app on OS X 10.6.1.

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

joebmaclap:mysql joeb$ sudo cd data
Password:

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

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?

link|improve this question
feedback

1 Answer

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).

link|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
feedback

Your Answer

 
or
required, but never shown