无法在 linux 控制台中执行任何基本命令

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/9437084/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-06 04:48:13  来源:igfitidea点击:

Can't execute any basic command in linux console

linuxbash

提问by Joe Almore

I know how the problem was created, but really have no idea how to restore the server command execution.

我知道问题是如何产生的,但真的不知道如何恢复服务器命令的执行。

The thing is, I was configuring the environment variables of Glassfish in my Ubuntu server, and I modified the .bashrcfile from root and added an exportclause (with GLASSFISH_HOMEvariable) and a PATHclause (pointing to the $GLASSFISH_HOME/bin).

问题是,我在我的 Ubuntu 服务器中配置了 Glassfish 的环境变量,我.bashrc从 root修改了文件并添加了一个export子句(带GLASSFISH_HOME变量)和一个PATH子句(指向$GLASSFISH_HOME/bin)。

Right after I close the console and open it again so the changes take effect, and (BAM!) once I start the new console session then none of the basic commands (dir, find, nano, ifconfig, anything) work now, I can only use cdto move in directories, I am trying to edit again the .bashrcfile to undo the changes but can't edit it either, none of the editors open! In the command line I only get -bash: dir: command not found.

在我关闭控制台并再次打开它以使更改生效后,(BAM!)一旦我开始新的控制台会话,那么现在基本命令(dir, find, nano, ifconfig, 任何东西)都不起作用,我只能使用cd移动在目录中,我试图再次编辑.bashrc文件以撤消更改,但也无法编辑它,没有任何编辑器打开!在命令行中,我只得到-bash: dir: command not found.

Please, if you have any solution for this; I know it seems trivial, but I'm kind of blind without being able to see or find the files and folders where commands/applications are located.

请,如果您对此有任何解决方案;我知道这看起来微不足道,但我有点盲目,无法查看或找到命令/应用程序所在的文件和文件夹。

采纳答案by Julien May

Do an export of the binary paths:

导出二进制路径:

export PATH=$PATH:/bin:/usr/bin

right after that you're able again to operate and to reverse your changes.

在那之后,您就可以再次操作并撤消更改。

Otherwise just do an edit with your favorite editor while given the full path to your editors binary:

否则,只需使用您最喜欢的编辑器进行编辑,同时给出您的编辑器二进制文件的完整路径:

/usr/bin/emacs -nw /root/.bashrc

回答by antlersoft

Probably you erased your path when you were changing the environment variables; this will prevent most commands from being found.

可能您在更改环境变量时删除了路径;这将阻止大多数命令被找到。

Fortunately, you can work around this by using the full path name when specifying the command.

幸运的是,您可以通过在指定命令时使用完整路径名来解决此问题。

vim doesn't work? Use /usr/bin/vim

vim 不起作用?使用 /usr/bin/vim

ls doesn't work? Use /usr/bin/ls

ls不行吗?使用 /usr/bin/ls

Most command you want to use will be in /usr/bin; if not found there you can check /bin or /usr/sbin

您要使用的大多数命令都在 /usr/bin 中;如果在那里找不到,您可以检查 /bin 或 /usr/sbin

With access to the editor you should be able to fix the startup script to get your path back.

通过访问编辑器,您应该能够修复启动脚本以恢复您的路径。

回答by Andrew Marshall

You've overwritten your $PATH, rather than appending to it, you probably have something like this in your .bashrc:

你已经覆盖了你的$PATH,而不是附加到它,你可能有这样的东西在你的.bashrc

export PATH=$GLASSFISH_HOME/bin

or similar, but you need to append the current $PATHto the end of it:

或类似的,但您需要将当前附加$PATH到它的末尾:

export PATH=$GLASSFISH_HOME/bin:$PATH

To edit this in the terminal, you will have to append /usr/binto your editor (e.g. /usr/bin/vim ~/.bashrc) until you correct the problem.

要在终端中编辑它,您必须附加/usr/bin到您的编辑器(例如/usr/bin/vim ~/.bashrc),直到您更正问题。

You may wish to read more about the $PATHvariable.

您可能希望阅读有关$PATH变量的更多信息