简体   繁体   English

Mac OS X终端问题

[英]mac os x terminal problem faced

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... 哦,天哪...我遇到了一个大问题...我在〜文件夹中创建了一个.bash_profile,然后在其中设置路径...最麻烦的是重新启动bash之后,我发现我的命令都无法像LS一样工作和RM等...

now i dont know how to fix it...some one help me...i need my terminal as soon as possible... 现在我不知道如何解决它...有人帮助我...我需要我的终端机尽快...

确保您要追加到现有的$ PATH。

PATH=$PATH:/Users/mthalman/bin

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. 当我编辑环境文件(包括bashrc,配置文件,登录名和其他文件)时,我总是尝试在退出编辑环境之前启动另一个shell。 This protects me from the possibility of breaking my environment so that I can't log in. 这可以保护我免受破坏环境的可能性,使我无法登录。

确保PATH包含通常的bin目录: /bin/usr/bin

First I would rename ~/.bash_profile to ~/old.bash_profile . 首先,我将~/.bash_profile重命名为~/old.bash_profile

Then open that up in TextEdit (as a plain text document) and verify how you have set your path. 然后在TextEdit中将其打开(作为纯文本文档),并验证您如何设置路径。

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. 如果您更喜欢使用vim / emacs / nano /,无论如何,重命名文件的操作将允许新的终端会话使用默认路径,因此从命令行开始应该没问题。

Then verify you haven't clobbered $PATH as suggested by @Mark Thalman, above. 然后确认您没有像上面的@Mark Thalman所建议的那样破坏$PATH

If you are in a Terminal Window, simply add in the /bin and /usr/bin back in your PATH. 如果您在终端窗口中,只需将/bin/usr/bin回PATH中即可。

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

That should allow all the basic Unix command to work once more. 那应该允许所有基本的Unix命令再次工作。 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! 不要在您的.profile中重置PATH!

As you discovered, you should never reset PATH in your `.bash_profile. 如发现的那样,您永远不要在.bash_profile中重置PATH。 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. 第一行将/usr/local/bin放在PATH之前,这意味着如果命令位于/usr/local/bin/usr/bin ,则将执行/usr/local/bin版本。 Many system admins will put alternative base system commands in /usr/local/bin . 许多系统管理员会将替代的基本系统命令放在/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. 例如,在Solaris上,他们可能会将VIM放在/usr/local/bin/vi ,因此在编辑文件时,您使用的是改进的VIM,而不是基本VI。

The second line appends your $HOME/bin to the end of $PATH . 第二行将$HOME/bin附加到$PATH的末尾。 That means if there's a /bin/ls and you have ~/bin/ls , the /bin/ls will be executed first. 这意味着如果有一个/bin/ls并且您有~/bin/ls ,那么将首先执行/bin/ls

Never set PATH from scratch because each Unix system might have commands that you to access elsewhere in the system. 切勿从头开始设置PATH,因为每个Unix系统可能都有您可以在系统其他位置访问的命令。 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. 例如,您的站点可能要求您使用X11,因此您要在PATH中使用/ usr / X11 / bin,或者在/opt/git目录下安装了GIT,并且在其中需要/opt/git/bin你的路。

Sometimes, base utilities like ls might be replaced with upgraded versions of these utilities. 有时,诸如ls类的基本实用程序可能会被这些实用程序的升级版本取代。 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. 在Solaris上,您具有基本的vils命令,大多数用户喜欢GNU ls命令,因为它使用颜色并且比普通VI更喜欢VIM。 I would included these utilities in /usr/local/bin and prepend that to my PATH. 我会将这些实用程序包含在/usr/local/bin并将其放在我的PATH之前。


And now a Word from a Sponsor 现在赞助商的话

As you probably discovered, Finder doesn't list hidden files. 您可能已经发现,Finder不会列出隐藏文件。 That's why you can't see .bash_profile in Finder. 这就是为什么您在Finder中看不到.bash_profile的原因。 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 . 我使用一个名为Path Finder的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. 有一个内置的终端和GUI Subversion客户端。

It's not cheap ($40), but you can download for free and try it out for 30 days. 它并不便宜(40美元),但是您可以免费下载并试用30天。

BTW, I have absolutely no relationship to Cocoatech except as a customer, and I make no money from people buying Path Finder. 顺便说一句,除了作为客户,我与Cocoatech完全没有关系,并且我从购买Path Finder的人中不赚钱。 It's just a tool I use. 这只是我使用的工具。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM