如何在 Linux 中从命令行打开一个新窗口(shell)?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6611425/
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
How do I open a new window (shell) from command line in Linux?
提问by user832351
I'm working with a tool right now that requires me to putty to a remote host, login, run a series of commands to start an engine, open a new window (and login again) to start a different engine, then open a third window (and again, login) to actually use the tool (leaving the engines running in those first two windows). I'd like to write a shell script to automate the process so that I could just open one window, type "sh whatever.sh" and be off and running, without physically opening the new windows and logging in again. However, I can't find a command to get me from one window to the next. Any thoughts?
我现在正在使用一个工具,该工具要求我将腻子粘贴到远程主机,登录,运行一系列命令以启动引擎,打开一个新窗口(并再次登录)以启动不同的引擎,然后打开第三个窗口(再次登录)以实际使用该工具(让引擎在前两个窗口中运行)。我想编写一个 shell 脚本来自动化这个过程,这样我就可以打开一个窗口,输入“sh what.sh”并关闭并运行,而无需物理打开新窗口并再次登录。但是,我找不到让我从一个窗口转到下一个窗口的命令。有什么想法吗?
采纳答案by phihag
You can just background the first processes by adding an ampersand (&
) to the command line or pressing Ctrl+Z
when it is running (and then enter bg
to let the process continue, more information about that with jobs
).
您可以通过&
在命令行中添加一个与号 ( ) 或Ctrl+Z
在它运行时按下(然后输入bg
以让进程继续,有关更多信息,请使用jobs
)来将第一个进程置于后台。
If that's not enough, you can create virtual shells with screenor tmux.
如果这还不够,您可以使用screen或tmux创建虚拟外壳。
If you've redirected X (i.e. you can access GUIs over ssh), you can also just start a new window by executing your favorite (GUI) console program, like xterm
, konsole
, gnome-terminal
, etc.
如果你重定向X(即你可以访问超过SSH的GUI),用户也可以直接通过执行启动一个新的窗口,你最喜欢的(GUI)控制台程序,如xterm
,konsole
,gnome-terminal
,等。
回答by Alex
Try typing in "konsole". That should open a new bash window and set the focus to it.
尝试输入“konsole”。这应该会打开一个新的 bash 窗口并将焦点设置在它上面。
回答by Raoul
Are you familiar with jobs on linux?
你熟悉 linux 上的工作吗?
nohup whatever_1.sh &
nohup whatever_2.sh &
nohup whatever_3.sh &
Or perhaps screen would be of use here:
或者 screen 可能在这里有用:
https://serverfault.com/questions/25301/job-control-and-ssh
https://serverfault.com/questions/25301/job-control-and-ssh
See also, nohup:
另见,nohup:
回答by Mihails Strasuns
Shell script on target machine cannot be aware of putty windows on client machine. Consider using Screen : http://www.gnu.org/s/screen/- it is clean and powerful way.
目标机器上的 Shell 脚本无法识别客户端机器上的腻子窗口。考虑使用 Screen :http: //www.gnu.org/s/screen/- 这是一种干净而强大的方式。
回答by abilashov
I think you need command line window then write:
我认为你需要命令行窗口然后写:
$ xterm
# new window started
If you need python in new window:
如果您需要在新窗口中使用 python:
$xterm python
#now a window will shown with python shell
回答by sfinley
The bash
command opens a Bourne-again shell (bash) session.
该bash
命令会打开一个 Bourne-again shell (bash) 会话。
回答by sfinley
On my Ubuntu 18 I just type the command:
在我的 Ubuntu 18 上,我只需输入命令:
gnome-terminal
and a new shell opens... I don't like the above answers because xterm
and konsole
most likely not already be installed.
并打开一个新的外壳......我不喜欢上面的答案,因为xterm
和konsole
最有可能尚未安装。
回答by simhumileco
Another nice option from Xfce's terminal:
Xfce 终端的另一个不错的选择:
xfce4-terminal