如何直接从命令行启动具有多个分割的屏幕?


13

我用screen我曾与登录后ssh到我的服务器。到目前为止,我已经在屏幕窗口中手动设置了拆分,并手动运行了命令,如以下屏幕截图所示:

在此处输入图片说明

  • 顶部应该运行tail -n 1 -f /home/server/log/access.log
  • 右下部分应该运行 htop
  • 左下角应该只是命令提示符

有什么方法可以通过命令/脚本来完成,所以我不必每次都手动重做?



@muru这部分回答了如何启动单独的屏幕,而不是部分如何如上图所示直接订购它们。
Videonauth

使用屏幕中的快捷方式可以完成的所有操作都可以使用中的命令来完成.screenrc。对于这种安排,我们有split命令
muru

Answers:


16

对于特定的窗口排列情况,有一个screen命令将它们保存到文件中:layout dump。来自man screen

layout dump [filename]

Write to a file the order of splits made in the current layout. This is
useful to recreate the order of  your  regions  used  in  your  current
layout.  Only  the  current  layout is recorded. While the order of the
regions are recorded, the sizes of  those  regions  and  which  windows
correspond  to  which regions are not. If no filename is specified, the
default is layout-dump, saved in the directory that the screen  process
was  started in. If the file already exists, layout dump will append to
that file. As an example:

           C-a : layout dump /home/user/.screenrc

will save or append the layout to the user's .screenrc file.

因此,一旦您手动进行了排列,请按Ctrla:,然后键入layout dump /path/to/some/file。布局将保存到/path/to/some/file,然后您可以使用以下命令在新会话中将其还原:

screen -c /path/to/some/file

+1好听的人;在split -v似乎无证:)这就是为什么我挣扎。
Videonauth

@Videonauth实际上记录在默认的快捷键部分下。 C-a | (split -v) Split the current region vertically into two new ones.
Sergiy Kolodyazhnyy

是的,它看起来只是在手册页中提到C-a |,而在GNU文档中却没有提及
muru

发现了您可能要提及的奇怪行为:如果键入,例如,layout dump ~/layout该过程将失败,则需要完整路径(即/home/$USER/layout
Videonauth

@Videonauth,因为波浪号扩展通常由外壳程序完成,因此如果给定的命令内部不支持它,也就不足为奇了。有些会,大多数不会。
muru

10

我想出了以下内容来创建问题中显示的输出,并遵循@muru的出色答案。使用layout dump给了我以下内容:

split
focus
split -v
focus

注意:Tilde(~)扩展不适用于此,layout dump而不是~/layout.dmp例如,您需要使用/home/<username>/layout.dmp

然后从中创建以下内容 .screenrc

# create the top screen
chdir /home/server/log
screen -t "Apache Log" tail -n 1 -f access.log
# split the screen and focus onto the new created space
split
focus
#create the bash
chdir /home/server/log
screen
# split vertically and focus onto the new area
split -v
focus
# create the htop screen
screen -t "Htop" htop
# focus twice to end up with the bash area active
focus
focus

现在,我只需要输入screen并开始想要的布局即可。我在这里以那些想知道的人为例,但不要忘了投票@muru的答案,因为他是使我能够解决此问题的人。

By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.