如何直接从命令行启动多个拆分屏幕?

我用ssh到服务器后,我正在使用screen 。 截至目前,我手动在屏幕窗口中设置分割并手动运行命令,如下面的屏幕截图所示:

在此处输入图像描述

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

有没有办法通过命令/脚本完成,所以我不必每次都手动重做它?

对于窗口排列的特定情况,有一个屏幕命令将它们保存到文件: 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: Ca : layout dump /home/user/.screenrc will save or append the layout to the user's .screenrc file. 

因此,一旦您手动进行排列,请按Ctrl a : ,然后键入layout dump /path/to/some/file 。 布局将保存到/path/to/some/file ,然后您可以在新会话中将其恢复为:

 screen -c /path/to/some/file 

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

 split focus split -v focus 

注意:Tilde( ~ )扩展不适用于layout dump所以代替~/layout.dmp ,例如你需要使用/home//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的答案投票,因为他是让我能够解决这个问题的人。