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 foundMy 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:
>ls
-bash: ls: command not found
-bash: sed: command not found
-bash: git: command not foundAny 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?
59 Answers
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
PATH=/home/user/bininstead of
PATH="$PATH":/home/user/bin 10 One way to begin debugging your bash script would be to start a subshell with the -x option:
$ bash --login -xThis 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: .
Ultimately, I think that January's suggestion will work for you, but that link is worth a read for future problems.
2I 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!
3After 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/binThis 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
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 -mAfter that, you can use
vim /root/.bashrcto edit PATH.
Goodluck!
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.
1I had exactly the same problem:
If I put in lxterminal:
set | grep "jerom/bash"
PATH=/usr/lib/lightdm/lightdm:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/home/jerom/bash/if I entered exactly the same command in tty2 I got:
set | grep "jerom/bash"
PATH=/usr/lib/lightdm/lightdm:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/home/jerom/bash\r\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 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! :)