Screen
Created: 2017-02-04 11:15:39 -0800 Modified: 2021-10-02 11:08:32 -0700
Basics
Section titled Basics-
List all available screens: screen -ls
-
Attach to a screen shown in “screen -ls”: screen -rd <name of screen>
- Note: I believe “attached” just means that that’s where your commands will go (switching between windows in the screen, killing screens, etc.).
-
Kill all screens: killall screen
-
Kill a single screen:
- ctrl+a, k
- ctrl+D (this is just a logout)
- ”$ exit” (this is just a logout)
-
To rename a screen: ctrl+a, capital A
-
Ctrl+A and then a shortcut is the way to interact with screen easily
- I can do this flow:
- <first time only> screen
- Ctrl+A c - make a window
- Ctrl+A A - title it “client”
- <launch the client>
- Ctrl+A c - make another window
- Ctrl+A A - title it “server”
- <launch the server>
- Close Putty if I want
- …later
- Reconnect with Putty
- screen -rd - reattach to the screen I had earlier
- Ctrl+A ” - choose which window I want
- Ctrl+D, d: detach back to the shell
- I can do this flow:
-
Scrolling a screen: ctrl+a, ctrl+[
- Then use arrows or page [up|down]
-
screen -rd: this reattaches to an existing screen, detaching first if necessary (e.g. if Putty was timed out and your bash session was still active).
- screen -list will show any active screen.
-
To create a new screen window from inside screen, just do “screen -t name”. You may need the “-p” option.
-
To make it so that your Bash profile is automatically loaded when you launch “screen”, you’ll need to edit your ~/.screenrc file
Turn off the startup message
Section titled Turn off the startup messagestartup_message off
I think this may be all that’s necessary for using bash_profile actually…
Section titled I think this may be all that’s necessary for using bash_profile actually…shell -$SHELL
”-t” is title. The number is the number that shows up when you press ctrl+A “
Section titled ”-t” is title. The number is the number that shows up when you press ctrl+A “The “-l” at the end of “bash” is to get it to simulate a login, that way
Section titled The “-l” at the end of “bash” is to get it to simulate a login, that wayyou’ll have access to the bash_profile functions.
Section titled you’ll have access to the bash_profile functions.screen -t bash 0 bash -l
screen -t bldeploy 1 bash -l
screen -t htop 2 htop
Section titled screen -t htop 2 htopSelect the first screen tab.
Section titled Select the first screen tab.select 0
- After making changes, if you want to source the screenrc file, do this: https://serverfault.com/a/194612
- Ctrl+A → type a colon → source ~/.screenrc
- Here’s an entire thread of people talking about their screenrc files.
Annotated Bash script for starting up commands in screen (written by HiDeoo):
WARNING #1: I’ve found that I need to add “sleep 0.1” after creating the screen or else subsequent commands don’t always work.
WARNING #2: your .screenrc file can get in the way of this sometimes. For example, if my screenrc is set to create tabs like “bash” and “htop”, then I don’t think “thingy1” below ever gets created. According to HiDeoo:
Also, if you find .screenrc files more readable / usable than a script, you can specify a path for a screenrc to use to screen with the -c option like screen -c useThisScreenrcInsteadOfTheDefaultOne.
Screenrc (reference)
Section titled Screenrc (reference)What’s nice about this screenrc is that you’ll be able to see the windows as “tabs” at the bottom of the terminal so that you can easily switch with ctrl+A, <number of tab>.
startup_message off
Section titled startup_message offshell -$SHELL
screen -t bash 0 bash -l
Section titled screen -t bash 0 bash -lscreen -t htop 5 htop
Section titled screen -t htop 5 htopselect 0
Section titled select 0Taken from https://gist.github.com/ChrisWills/1337178
Section titled Taken from https://gist.github.com/ChrisWills/1337178GNU Screen - main configuration file
Section titled GNU Screen - main configuration fileAll other .screenrc files will source this file to inherit settings.
Section titled All other .screenrc files will source this file to inherit settings.Author: Christian Wills - cwills.sys@gmail.com
Section titled Author: Christian Wills - cwills.sys@gmail.comAllow bold colors - necessary for some reason
Section titled Allow bold colors - necessary for some reasonattrcolor b “.I”
Tell screen how to set colors. AB = background, AF=foreground
Section titled Tell screen how to set colors. AB = background, AF=foregroundtermcapinfo xterm ‘Co#256:AB=E[48;5;%dm:AF=E[38;5;%dm’
Enables use of shift-PgUp and shift-PgDn
Section titled Enables use of shift-PgUp and shift-PgDntermcapinfo xterm|xterms|xs|rxvt ti@:te@
Erase background with current bg color
Section titled Erase background with current bg colordefbce “on”
Enable 256 color term
Section titled Enable 256 color termterm xterm-256color
Cache 30000 lines for scroll back
Section titled Cache 30000 lines for scroll backdefscrollback 30000
New mail notification
Section titled New mail notificationbacktick 101 30 15 $HOME/bin/mailstatus.sh
Section titled backtick 101 30 15 $HOME/bin/mailstatus.shhardstatus alwayslastline
Very nice tabbed colored hardstatus line
Section titled Very nice tabbed colored hardstatus linehardstatus string ’%{= Kd} %{= Kd}%-w%{= Kr}[%{= KW}%n %t%{= Kr}]%{= Kd}%+w %-= %{KG} %H%{KW}|%{KY}%101`%{KW}|%D %M %d %Y%{= Kc} %C%A%{-}‘
Troubleshooting
Section titled TroubleshootingScreen inside screen - how to use (reference)
Section titled Screen inside screen - how to use (reference)“Ctrl+A A” becomes your shortcut instead of just “Ctrl+A”