mac os x terminal problem faced

梦想的初衷 提交于 2020-01-05 08:52:20

问题


oh my god...i faced a big problem...i was created a .bash_profile in ~ folder and then set paths there...bust the big problem is after restarting my bash i see that none of my commands work like LS and RM and etc...

now i dont know how to fix it...some one help me...i need my terminal as soon as possible...


回答1:


Make sure you are appending to the existing $PATH.

PATH=$PATH:/Users/mthalman/bin



回答2:


To prevent this happening in the future:

When I edit my environment files (including bashrc, profile, login, and others), I always try starting another shell before quitting my editing environment. This protects me from the possibility of breaking my environment so that I can't log in.




回答3:


Make sure your PATH includes the usual bin directories: /bin and /usr/bin.




回答4:


First I would rename ~/.bash_profile to ~/old.bash_profile.

Then open that up in TextEdit (as a plain text document) and verify how you have set your path.

If you would prefer to use vim/emacs/nano/whatever, the act of renaming the file will allow new terminal sessions to use default paths, so from the command line you should be mostly fine.

Then verify you haven't clobbered $PATH as suggested by @Mark Thalman, above.




回答5:


If you are in a Terminal Window, simply add in the /bin and /usr/bin back in your PATH.

$ PATH="/bin:/usr/bin:$PATH"

That should allow all the basic Unix command to work once more. Or, you can use the full path name for commands:

$ PATH=""  #Can't find nothin'
$ ls
bash: ls: command not found.
$ /bin/ls -a  #This will work!
.   ..   .bash_profile   foo   bar

Don't Reset PATH in your .profile!

As you discovered, you should never reset PATH in your `.bash_profile. Instead, you should always append and prepend to it:

PATH="/usr/local/bin:$PATH"
PATH="$PATH:$HOME/bin"

The first line will prepend /usr/local/bin to PATH which means if a command is in /usr/local/bin and /usr/bin, the /usr/local/bin version will be executed. Many system admins will put alternative base system commands in /usr/local/bin. For example, on Solaris, they might put VIM in /usr/local/bin/vi, so when you edit a file, you're using the improved VIM and not the base VI.

The second line appends your $HOME/bin to the end of $PATH. That means if there's a /bin/ls and you have ~/bin/ls, the /bin/ls will be executed first.

Never set PATH from scratch because each Unix system might have commands that you to access elsewhere in the system. For example, your site might require you to use X11, so you want /usr/X11/bin in your PATH, or you have GIT installed under the /opt/git directory, and you'll need /opt/git/bin in your path.

Sometimes, base utilities like ls might be replaced with upgraded versions of these utilities. On Solaris, you have the base vi and ls command, Most users like the GNU ls command because it uses color and prefer VIM to plain VI. I would included these utilities in /usr/local/bin and prepend that to my PATH.


And now a Word from a Sponsor

As you probably discovered, Finder doesn't list hidden files. That's why you can't see .bash_profile in Finder. You can use some hacks to change this, but it requires you to type them into the terminal window.

I use a Finder replacement called Path Finder. It contains a lot of neat Power User things such as allowing you to see hidden files, treat Packages such as apps as directories, and be able to view protected directories if you have Administrator access. There's a built in terminal and GUI Subversion client.

It's not cheap ($40), but you can download for free and try it out for 30 days.

BTW, I have absolutely no relationship to Cocoatech except as a customer, and I make no money from people buying Path Finder. It's just a tool I use.



来源:https://stackoverflow.com/questions/5248622/mac-os-x-terminal-problem-faced

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!