How do I start screen with multiple splits directly from the command line?
For the specific case of window arrangements, there's a screen command to save them to a file:
layout dump. From
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
I came up with the following to create the output shown in my question and following @muru's excellent answer. Using
layout dump gave me the following:
split focus split -v focus
Note: Tilde (
~) expansion does not work with
layout dumpso instead of
~/layout.dmpfor example you would need to use
From which I then created the following
# 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
Now I only need to type
screen and get my wanted layout started. I leave that here as an example for those who are wondering, but don't forget to up-vote @muru's answer, since he is the one who made me able to solve this.
Related videos on Youtube
Videonauth 5 months
screenafter I have logged in with
sshto 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:
- The top part should run
tail -n 1 -f /home/server/log/access.log.
- The lower right part should run
- 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?
muru about 5 years
Videonauth about 5 years@muru This quite answers it for the part how to start the separate screens, just not the part how to have them directly ordered like above shown.
muru about 5 yearsEverything that can be done using shortcuts in screen can be done using commands in
.screenrc. For this arrangement we have the
- The top part should run
Videonauth about 5 years+1 nice one; The
split -vseems undocumented :) this is why I was struggling.
Sergiy Kolodyazhnyy about 5 years@Videonauth it actually is documented under default keybindings section.
C-a | (split -v) Split the current region vertically into two new ones.
muru about 5 yearsYes, it looks it's only mentioned in the manpage, next to
C-a |, but not in the GNU docs
Videonauth about 5 yearsFound an odd behavior you might want to mention: If you type for example
layout dump ~/layoutthe process will fail, it need to full path (i.e.
muru about 5 years@Videonauth since tilde expansion is usually done by the shell, it's not surprising if a given command doesn't support it internally. Some do, most don't.
dojuba over 4 yearsI can't dump the layout from a detached session by following:
screen -r SESSION_NAME -X layout dump FILE_NAME. Other commands work fine with