无法在 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
Can't execute any basic command in linux console
提问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 .bashrc
file from root and added an export
clause (with GLASSFISH_HOME
variable) and a PATH
clause (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 cd
to move in directories, I am trying to edit again the .bashrc
file 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 $PATH
to the end of it:
或类似的,但您需要将当前附加$PATH
到它的末尾:
export PATH=$GLASSFISH_HOME/bin:$PATH
To edit this in the terminal, you will have to append /usr/bin
to 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 $PATH
variable.
您可能希望阅读有关$PATH
变量的更多信息。