How to Start Screen with Multiple Splits from Command Line

command linegnu-screen

I'm using screen after I have logged in with ssh to my server. As of now I set up the splits in my screen window by hand and run the commands by hand as shown in the following screen-shot:

enter image description here

  • The top part should run tail -n 1 -f /home/server/log/access.log.
  • The lower right part should run htop
  • The lower left one should simply be a command prompt

Is there any way to have that be done via commands/script, so I not have to redo it every time by hand?

Best Answer

For the specific case of window arrangements, there's a screen command to save them to a file: layout dump. From 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.

So, once you make the arrangement manually, press Ctrla:, then type layout dump /path/to/some/file. The layout will be saved to /path/to/some/file and you can then restore it in a new session with:

screen -c /path/to/some/file
Related Question