Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

The majority of Terminal command, "not found"

When I was trying to mess around with my Kinect camera on my iMac today, via Terminal, I noticed a peculiar thing occurring when I tried to use even the most basic of Terminal commands.

For example, I typed in "ls" to try to list the directories and files of my current directory, but was presented with the following instead:

"-bash: ls: command not found"

Without the quotes obviously.

Why is this happening? Should I be concerned?

iMac W87400H6X8A, Mac OS X (10.5.6), iMac 24" 2.4GHz

Posted on Nov 17, 2010 3:21 PM

Reply
Question marked as Best reply

Posted on Nov 17, 2010 3:54 PM

It sounds like you've got a bad PATH variable. Try entering this in the window which is misbehaving:

/bin/echo $PATH

Paste the result back here. I'm just guessing that this is the issue. The result should look something like this (copied from my 10.6 system with a few mods).

/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/local/drush:/usr/local/git/bin :/usr/local/mysql/bin:/opt/local/bin:/opt/local/sbin:/usr/X11/bin


--

Open a new Terminal window and see if the problem occurs there too.

If it does, then either
1. Bash isn't getting told where to look for executables (via the $PATH variable), which is an easy fix.
2. Your system path folders are hosed, and you're in more serious trouble.
10 replies
Question marked as Best reply

Nov 17, 2010 3:54 PM in response to Qcom

It sounds like you've got a bad PATH variable. Try entering this in the window which is misbehaving:

/bin/echo $PATH

Paste the result back here. I'm just guessing that this is the issue. The result should look something like this (copied from my 10.6 system with a few mods).

/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/local/drush:/usr/local/git/bin :/usr/local/mysql/bin:/opt/local/bin:/opt/local/sbin:/usr/X11/bin


--

Open a new Terminal window and see if the problem occurs there too.

If it does, then either
1. Bash isn't getting told where to look for executables (via the $PATH variable), which is an easy fix.
2. Your system path folders are hosed, and you're in more serious trouble.

Nov 17, 2010 4:00 PM in response to xurizaemon

Hey, thanks for the clear instructions!

Here is the output from a new Terminal window (I closed the previous window but it was a new one to begin with):

/usr/local/mysql/bin:??

Aha! It looks like my MySQL install screwed it up somehow. I'm hoping this falls into problem number 1 that you listed below! xD

And, I'm running 10.6.5

Nov 17, 2010 6:15 PM in response to Qcom

Also, I'm not sure if this matters, but I think this has to do with the problem, whenever I start up a new Terminal window, there is the following prompt on the very first line:

Last login: Wed Nov 17 17:42:53 on ttys000

I'm assuming this has to do with the MySQL confusion. Is there any ay to log out of it or something ? I don't think I had this problem prior to messing around with MySQL, and I'm not very good with MySQL..

Nov 17, 2010 6:23 PM in response to Qcom

xurizaemon has properly identified the problem.

The easy solution is to remove or rename the .profile or .bash_profile that most likely was created during the MySQL installation.

ls -a $HOME
mv .profile saved.profile
mv .bash_profile saved.bash_profile

Restart your Terminal session and you will have full access to the normal set of commands.

Assuming the only change was attempting to add /usr/local/mysql/bin, you could try creating a new .bash_profile

echo 'export PATH=$PATH:/usr/local/mysql/bin' >$HOME/.bash_profile

You should be able to copy and paste the above 'echo' command directly into the terminal (after having done the previous rename (mv) operations). Then restart your Terminal session.

Then again, if you have a lot more stuff in your .profile or .bash_profile, then you need to figure out how to edit your shell initialization file. Fraise or TextWrangler can edit hidden files along with the 'nano' command.

Nov 17, 2010 7:18 PM in response to Qcom

Thanks for that, great, except for the fact that "mv" doesn't exist, it says "command not found"! xD

What's the full path for the "mv" command?

D'oH! My Bad 😟


/bin/ls -a $HOME
/bin/mv .profile saved.profile
/bin/mv .bash_profile saved.bash_profile

Restart your Terminal session and you will have full access to the normal set of commands.

Assuming the only change was attempting to add /usr/local/mysql/bin, you could try creating a new .bash_profile

echo 'export PATH=$PATH:/usr/local/mysql/bin' >$HOME/.bash_profile

Nov 17, 2010 7:53 PM in response to Qcom

great to hear that you're just dealing with a bad PATH variable 🙂

So, there are a few things which could be setting your $PATH.

The most likely files are .profile and .bash_profile, but there are a few others.

There's .profile and .bash_profile. There's also .bashrc which is called per session*.

On OSX there's also /etc/paths.d (a directory) which packages may install additional paths into (one PATHSPEC per file I believe.

Your options are
1) to open the files which are messing things up and fix them (this is what I'd do, because I have other configurations which I've added to ~/.bash_profile and I'd be sad to lose those). I'd probably open them in an editor and comment (# like this) out any references to PATH there.
2) to simply move those files out of the way and see if that fixes the problem. Probably safer provided you aren't fussy about reverting to default configs. At this point, you're probably OK with that 😀

If looking in your ~/.profile etc, you might also see "source /some/other/file" or ". ~/.some otherfile". If so, those files are being included in your bash login scripts; you might want to debug them too.

Good luck!

* Unix greybeards, I'm a little vague on this, please be gentle.

Nov 18, 2010 6:34 AM in response to Qcom

Is there any reason why I don't have a ".profile saved.profile" or a ".bash_profile saved.bash_profile"?

It just displays:

"No such file or directory".

Ouch! By default there are no shell initialization files. I was assuming that the MySQL installation created either a .profile or a .bash_profile, or the instructions had you manually creating one of them.

If you do not have a .profile nor a .bash_profile, then I'm not sure where the MySQL installation put them.

But just to be on the safe side and make sure we are looking in the correct directory try:

echo $HOME # just want to make $HOME variable is properly setup.
/bin/ls -l $HOME/.profile $HOME/.bash_profile $HOME/.bash_login $HOME/.bashrc

I apologize if I missed some of your explanations, I don't mean to be fussy!

Your Terminal sessions are not working. I would be more than "fussy" if that happened to me! Then again, I live inside of terminal sessions 🙂

xurizaemon had an earlier post where he listed some additional places that PATH could be modified.

/bin/cat /etc/profile
/bin/ls -R /etc/paths.d

You might go back and re-read what xurizaemon wrote in that post.

Another thing you could try is, using System Preferences -> Accounts, create a new account, and see if that account has the same Terminal problem (this is an experiment, not a solution). If it does, then it would seem the changes were global, so the /etc/profile, and /etc/paths.d locations are candidates. If the problem does NOT occur for a new account, then this would point to $HOME/.profile, $HOME/.bash_profile, $HOME/.bash_login.

Message was edited by: BobHarris

The majority of Terminal command, "not found"

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple ID.