I was updating my .bash_profile, and unfortunetly I made a few updates and now I am getting:

env: bash: No such file or directory
env: bash: No such file or directory
env: bash: No such file or directory
env: bash: No such file or directory
env: bash: No such file or directory
-bash: tar: command not found
-bash: grep: command not found
-bash: cat: command not found
-bash: find: command not found
-bash: dirname: command not found
-bash: /preexec.sh.lib: No such file or directory
-bash: preexec_install: command not found
-bash: sed: command not found
-bash: git: command not found

My bash_profile actually pulls in other .sh files (sources them) so I am not exactly sure which modification may have caused this.

Now if I even try and to a list of files, I get:

-bash: ls: command not found
-bash: sed: command not found
-bash: git: command not found

Any tips on how to trace the source of the error, and how to be able to use the terminal for basic things like listing files etc?

  • What happens if you use the full path like so: /bin/ls ? And what sorts of changes were you making? – K. P. MacGregor Sep 12 '12 at 2:24
  • 2
    Yes, paste your .bash_profile – January Sep 12 '12 at 2:32
  • /bin/ls lists the files, but then I see these 2 lines below it: -bash: sed: command not found -bash: git: command not found – Blankman Sep 12 '12 at 2:40

It looks to me that at one point or another you are overwriting the default PATH environment variable. The type of errors you have, indicates that PATH does not contain /bin, where the above commands (including bash) reside.

For example, if you do


instead of

  • I did do this at one point: export PATH=PATH:EC2_HOME/bin – Blankman Sep 12 '12 at 2:45
  • 2
    You have to use '$' in the second PATH string - export PATH=$PATH:EC2_HOME/bin – Manula Waidyanatha Sep 12 '12 at 2:53
  • strange how 'ec2-describe-regions' doesn't work, even though it is in my path, yet this works: $EC2_HOME/bin/ec2-describe-regions I did a source reload also.... – Blankman Sep 12 '12 at 2:59
  • 2
    Look, we don't know what you are doing, what other files you are sourcing, what is in them. And yes, every time you source the file, you append things to your path (which is fine, because normally .bash_profile will get read only once). Go through it one by one and see what happens. Also, isn't EC2_HOME a variable? If yes, then you should precede it with a $ like this: export PATH=$PATH:$EC2_HOME/bin – January Sep 12 '12 at 3:07
  • 1
    I lose count of how much times I stucked into that problem and how much times this answer helped me a lot – Herrgott Nov 20 '18 at 13:32

One way to begin debugging your bash script would be to start a subshell with the -x option:

$ bash --login -x

This will show you every command, and its arguments, which is executed when starting that shell.

The --login option is specified because .bash_profile is read by login shells. Further information on debugging bash scripts can be found here: http://tldp.org/LDP/Bash-Beginners-Guide/html/sect_02_03.html.

Ultimately, I think that January's suggestion will work for you, but that link is worth a read for future problems.


I may have found the problem. It worked for me, and it might work for you...

I was defaulting with my editor to Windows (LF/CR) saves. Since I use both systems, it seemed logical. When I needed to mess with my .bash_profile, I realized after commenting out and tryig things that nothing worked. I changed my saves to OS X format (CR only) and voilà! No more "command not found" in the terminal!

It may just be that easy!

  • Very subtle thing that was driving me crazy. Thanks for adding this answer! – samuel.molinski May 7 '14 at 20:51
  • This was what I was experiencing! Thanks. Quick tip is using this command to convert files on your unix environment: $ dos2unix .bash_profile – melwil Dec 2 '16 at 8:43
  • Are you sure that's what you did? Since OS X is Unix it uses Unix-style line endings with a single linefeed (LF) character, not carriage return (CR). The only popular operating system that used the latter were OS 9 and prior and Linux/Ubuntu applications would be quite confused by it. – David Foerster Apr 30 '18 at 9:02

After I couldn't re-run . ~/.bash_profile or any usual commands like whoami, grep, etc. I figured a way to just re-export the required paths:

export PATH=/usr/local/jdk/bin:/usr/kerberos/sbin:/usr/kerberos/bin:/usr/local/sbin:usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/opt/cpanel/composer/bin:/usr/local/easy/bin:/usr/local/bin:/usr/X11R6/bin:/root/bin

This should work in most systems, although some of these paths are not present in all Linux packages. It worked for me.


I think I may have found the answer to the problem if not for you then for others who have a similar problem. My answer to this is that I do not have a .bash_profile.

So I was searching all over the web and I found the solution. Which is basically open the terminal, type touch ~/.bash_profile and press Enter. That fixed my problems. Hope it does the same for you

  • 6
    LOL... -bash: touch: command not found – Kumar KL May 5 '16 at 7:11

I have the same problem like you. I can't use many popular command (ls, vi/vim, ..) and can't edit /root/.bashrc when I log in with su into root.

Finally. I found the solution for this problem. Just login root with command:

su -m

After that, you can use

vim /root/.bashrc

to edit PATH.



I had exactly the same problem:

If I put in lxterminal:

set | grep "jerom/bash"

if I entered exactly the same command in tty2 I got:

set | grep "jerom/bash"

\r means DOS end of line, so I opened file ~/.bashrc and change the ends of lines in Krusader to unix style. And its working already!!! :-)

The DOS EOLs make spourious problems also in bash scripts.


I had the same problem. You may have missed a $ while exporting PATH. You should open the .bash_profile in TextEdit. If you can't find the file in the directory, press Command + Shift + > to show hidden files.

Then make correction to the PATH and then save.

In the directory on Terminal, type: source .bash_profile.

This should resolve the issue.


I got the same problem just now after I changed the .bash_profile. And I want to change it back but now I can't, because I lost all the commands, especially the nano command and the vim command, so I can't open the .bash_profile with command. And the .bash_profile is a hidden file I can't open it with the Finder.

So I need to find a way to open the .bash_profile file. After I tried many ways I found that I can use Atom, because Atom can read all files in a project folder, include the hidden files. So just open Atom, and select the File -> Open, choose <yourusername> folder, and then, all hidden files is showing on the Atom's tree view, include the .bash_profile!! After I removed the last modification and reopen the Terminal, all commands came back! :)

protected by heemayl Feb 6 '17 at 4:06

Thank you for your interest in this question. Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).

Would you like to answer one of these unanswered questions instead?

Not the answer you're looking for? Browse other questions tagged or ask your own question.