"-bash: ls: command not found"

Solution 1:

Since two commands are missing something “stomped” your path.

Before doing anything big, kicking off a backup might be prudent.

The default path on Mac OS X 10.7 (Lion) is something like this:

PATH=/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/bin

If you reset the path by typing the above into a shell window, and then typing export PATH it should manually let you test s local fix that window only.

This breakage is almost always something you need to fix in your dot files. For bash, edit and fix .bash_profile and/or .bashrc by undoing a recent change it just setting the $PATH you need again. The usual error is assigning a new path and not referring to the previous value of the variable on the right hand side of the =

Solution 2:

This should fix the problem completely and permanently.

first, export environment paths by using below command in the terminal.

export PATH=/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/b‌​in

now you have the commands you want. (eg. try ls. You'll see the command is working). But this is only for the current session. If you close the terminal and open a new one, you will have the previous issue. To make this change permanent, use below command,

go to home directory

cd ~

open .bash_profile file in nano / vim (I'm using nano here)

nano .bash_profile

This will open up nano editor. In a new line, paste the following;

export PATH=/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/bin:$PATH

press 'control'+'o' to save (WriteOut) and 'control'+'x' to exit nano.

All done ! Now try the commands.

Solution 3:

To check that it is indeed a problem with your path, what's the result of /bin/ls ?

If it works, than you should restore your path to /usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/bin, you can use for example VI whose path is (on my mac) /usr/bin/vi.