当基本命令不起作用时,如何在〜/.bashrc中还原我的PATH? [英] How do I restore my PATH in ~/.bashrc when basic commands don't work?

查看:280
本文介绍了当基本命令不起作用时,如何在〜/.bashrc中还原我的PATH?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Ubuntu上安装程序时,我弄乱了〜/.bashrc中的路径.现在,我无法使用ls,vim等Linux命令.因此,我无法编辑〜/.bashrc文件(它是一个群集).如何修复我的Shell启动文件?

While installing a program on Ubuntu, I messed up paths in my ~/.bashrc. Now I cannot use Linux commands like ls, vim, etc. Therefore I cannot edit the ~/.bashrc file (it's a cluster). How can I fix my shell startup files?

推荐答案

为您的编辑者指定完全限定的路径

指定编辑器的绝对路径(例如vim,nano或emacs)通常可以使您修复Shell启动文件.例如,要编辑并重新获得您的Bash资源文件,请执行以下操作:

Specify a Fully-Qualified Path to Your Editor

Specifying an absolute path to your editor (e.g. vim, nano, or emacs) will generally enable you to fix up your shell startup files. For example, to edit and re-source your Bash resource file:

/usr/bin/nano ~/.bashrc &&
    . ~/.bashrc

创建一个干净的环境

如果您只想启动一个新的Shell,而不继承您当前的环境或获取您当前的.profile或.bashrc文件,则可以执行此操作.例如:

Start a Clean Environment

If you just want to start a new shell without inheriting from your current environment or sourcing your current .profile or .bashrc file, you can do that. For example:

/usr/bin/env -i /bin/bash --noprofile --norc

然后,您应该能够依靠可靠的系统默认设置来编辑 PATH 或其他设置,然后手动采购Shell的启动文件,或者仅使用以下命令执行新的Shell:

You should then be able to rely on sane system defaults to edit your PATH or other settings before sourcing your shell's startup files manually or just execing a new shell with:

command exec /bin/bash

在当前Shell中覆盖PATH

您也可以尝试使用标准的 getconf 实用程序使用系统默认值覆盖当前shell中的PATH.例如:

Override PATH in the Current Shell

You might also try overriding the PATH in your current shell with system defaults using the standard getconf utility. For example:

export PATH=$(command getconf PATH)

您还可以将PATH手动设置为最小的默认值,例如:

You can also set your PATH manually to a minimal sane default like:

export PATH=/usr/bin:/bin:/usr/sbin:/sbin

因此您可以继续处理您的问题.

so you can continue to work on your issue.

这方面可能不在编程的网站范围内,尤其是因为我们没有足够的关于您的系统的信息.通常,如果您弄乱了系统范围或群集环境设置,则可能需要查看/etc/profile、/etc/profile.d、/etc/skel、NFS共享或您的帐户或其他位置中的值.正在设置应用程序PATH.

This aspect is likely outside the scope of a site about programming, especially since we don't have enough information about your systems. In general, if you messed up system-wide or clustered environment settings, you may need to look at values in /etc/profile, /etc/profile.d, /etc/skel, NFS shares, or other locations where your account or application PATH is being set.

如果该问题是帐户的本地问题,那么我上面提供的提示将有所帮助.您可能还会考虑登录另一个没有相同问题的帐户.

If the problem is local to an account, then the tips I provided above will help. You might also consider logging into another account that doesn't exhibit the same problems.

知道要解决多系统配置问题的位置,或者知道系统或用户特定的PATH设置应该是什么,都不属于合理的Stack Overflow问题.除此之外,上面的任何解决方案都应该起作用.

Knowing where to fix a multi-system configuration issue, or knowing what your system- or user-specific PATH settings should be, is outside the scope of a reasonable Stack Overflow question. Short of that, though, any of the solutions above should work.

这篇关于当基本命令不起作用时,如何在〜/.bashrc中还原我的PATH?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆