首页 > 解决方案 > 如何通过在 linux 的另一个终端中发出命令来关闭 GNOME 终端?

问题描述

我在 Linux 中使用 gnome 命令打开了一个 gnome 终端作为新的不同窗口终端。现在我想要的是我只想通过在另一个终端中给出某个命令来关闭那个 gnome 终端。我尝试了一个命令作为“kill PID”,但是两个终端都关闭了。任何人都可以通过在另一个终端中编写命令来帮助我如何仅关闭 gnome 终端吗?

标签: gnome-terminal

解决方案


使用“xdotool”将 alt+F4 发送到目标窗口。用您的 windowID 替换零:

xdotool windowactivate --sync 00000000 key --clearmodifiers alt+F4

您可以使用“xdotool search”来获取windowID。在引号之间插入终端标题:

xdotool search --name "text_to_search"

加入所有命令:

xdotool windowactivate --sync $(xdotool search --name "text_to_search") key --clearmodifiers alt+F4

如果需要,添加“--delay 100”以获得更好的性能。


要安装“xdotool”类型:

sudo apt-get install xdotool

推荐阅读