为什么我的 bash 终端无法识别 shell 中的任何命令?

Ben*_*min 4 linux fedora bashrc

应一些用户的要求,我决定将所有中间步骤和结果添加到我的初始帖子中,以便用户可以更好地引导我完成解决方案。这是在标题中加入附加的问题如下。在“添加”下方有一个名为“解决方案”的部分,我在其中添加了为解决此问题而采取的额外步骤:

题:

今天,当我试图继续在命令行 shell 中运行我的代码时,我注意到 Fedora 21(i686 上的内核 4.1.13-100.fc21.i686(tty2 ))。我想如果我重新启动并重新启动系统,问题应该会解决。然而,令我惊讶的是,我注意到登录后系统没有启动。我尝试在屏幕变黑时按 CTRL+ALT+F2 来进行诊断,以查看它实际停止工作的位置。我看到完全停止的最后一行是说:

等待普利茅斯启动屏幕退出

在 shell 的诊断模式下实际上没有接受任何命令时,您是否介意让我知道如何通过说以下内容来解决此类问题?

-bash: <...>: 命令未找到

The only thing I can think of is some possible automatic update that I was not aware of or messing my .bashrc (which I can no longer see inside it by using the following command:)

sudo gedit ~/.bashrc


Additions:

I was able to login to my system only after entering the diagnostic mode by pressing Ctrl+Alt+F2 right after reboot and login into the main startup which fails under normal conditions.

Fedora release 21 (Twenty One)
Kernel 4.1.13-100.fc21.i686+PAEdebug on an i686 (tty2)

In this mode, then the login prompt appear

localhost login:

After entering my username, then it says:

Password:

After entering my password, then it says:

Last login: Wed Mar 30 15:33:54 on tty2

[bbenjamin@localhost ~]$

It is here that none of the commands are recognized by the shell no matter what. And the error message is usually:

-bash: <...>: command not found

where <...> is basically any command. The only time I was successful in getting most commands get realized by the shell was when I ran the following code (as mentioned by in the answer):

PATH=/usr/bin:/usr/sbin
Run Code Online (Sandbox Code Playgroud)

After which at least I could look for and see my files and folders and programs (since most commands are getting realized.)

However, I still need to logging normally so that I can make use of all the graphics and other features of Fedora which is impossible in the diagnostic mode. To make this possible in particular I need to open my .bashrc file and fix its issues permanently (assuming that I can have access to its original version somehow.) To do this, I need to run commands like

(sudo) gedit ~/.bashrc
Run Code Online (Sandbox Code Playgroud)

However, I am receiving error messages like:

Unable to init server: Could not connect: Connection refused

(gedit:1397): Gtk-WARNING **:cannot open display:

or running commands like this one:

~/.bash_profile
Run Code Online (Sandbox Code Playgroud)

which would yield error message:

bash: /home/bbenjamin/.bash_profile: Permission denied.

Now, learning from the answer, I am not supposed to run this latter command as it is not executable. And instead I should run it in the following format:

source ~/.bashrc
Run Code Online (Sandbox Code Playgroud)

After which I don't know how to proceed.

However, I don't know why the former command (sudo) gedit ~/.bashrc is not working either. I remember that I always used to make slight changes in the .bashrc file depending on my need. This time I don't know how I made changes in it that it caused all the issues explained here. So now, my question is whether there is a command-line based method that I can open .bashrc and look inside it and make needed changes permanently so my system logins appropriately leads me into its normal graphical mode where I see and utilize all Fedora features.


Resolution

I learned that once I am in the diagnostic mode through the command Ctrl+Alt+F2 right after unsuccessful login, I can temporarily fix the messed up file .bashrc by running the command PATH=/usr/bin:/usr/sbin. Then I could take a look inside my .bahsrc file through running the command line cat .bashrc. It was only then that I saw the contents of the file in which I had several paths added to the file. Since I had kept a record of my added files at the bottom of previous paths in a chronological order, I knew that the problematic path was the very last one. Now, in order to fix the issue, I had to actually modify the file. This was achieved by the command line nano .bashrc after which a new page appeared in which I had the chance of commenting out the problematic line by adding # in front of it. At the end, I saved my changes and exited. The last step I had to make was to reboot the system with its new modified .bashrc file through the command line telinit 6 after which the logging proved to be successful.

mat*_*tdm 5

It sounds like you put something in your ~/.bashrc which is causing PATH to be set in a way that doesn't include /usr/bin, which is where most programs actually live. If you run this:

PATH=/usr/bin:/usr/sbin
Run Code Online (Sandbox Code Playgroud)

most commands should start working — and then you can edit ~/.bashrc and fix whatever is resetting PATH there. (And, actually — you want to set PATH in ~/.bash_profile instead of ~/.bashrc — see How to correctly add a path to PATH?)

(Note, by the way, that no Fedora update would mess with this, as updates don't alter files in your home directory. Sometimes when you run updated software that software might update its own config files, but that doesn't apply to ~/.bashrc.)


在您的编辑中:gedit文本编辑器仅在图形模式下工作。在文本模式下,您需要一个基于文本的编辑器。其中最简单的可能是nano. 安装它

dnf安装nano

然后nano改用 if gedit。实际的编辑功能会有所不同,但非常简单。