Some time ago somebody told me about 'screen' in an irc chat. He just started to use screen and enjoyed the power of this command and wanted to share this experience with me. I now use this tool very often when I work on a remote system and other people should be able to follow the command I entered and which results I get. This was in particular useful when people asked for help because they had issues with Linux and they allowed me to access their system. That way they easily were able to follow all the activities I executed on their system. But it's also for other tasks very helpful and I now use it quite often.
I just checked the man page of screen and detected there are much more features available. I summarize the features on the following pages and list useful keyboard shortcuts.
Useful scenarios for screen:
- Multiple people want so share the command screen and want to see the commands entered and the results.
- User 1 enters screen
- User 2 commects from a remote system to the sytsem of User 1 and enters screen -x. Now both see and share the same console screen and can type any commands in parallel. So there is some synchronization required. I found it useful to communicate on the screen commandline. Just prefix any message with # and bash will treat this as a comment and will not write any error messages.
- You work on a remote system where you logged on with ssh and you need multiple screens in parallel
- Create a screen with screen and open othe screens with CTRL-a c and scroll between the screens with CTRL-a n and CTRL-a p.
- There are long runing tasks on a remote system which have to be controlled
- Create a screen with screen and move them in the backround with CTRL-a d. Now logoff from the system. Later on logn to the system again and reconnect to the previous session with screen -r and continue to work on the command line
- If you want to start a program during boot of the system with screen just add following line in /etc/crontab and then you can use the previously mentioned commands to connect later to the screen session
@reboot root /usr/bin/screen -dmS "<ScreenSessionName>" <absolutePathToProgram>
- You have to fix an issue on a system and have to jump between various dictionaries. You have to create a screen with screen and additional screens with CTRL-a c and jump between the screens with CTRL-a n and CTRL-a p
If you use a graphical desctop you can open multiple windows in parallel which is similar to what's described bove. But in most situations a GUI is overkill if you have to do some system maintenance or even dangerous,if you have to access a server with X as root. For securiity reasons a server should not have a running X. That's why every administration should be executed from a commandline via ssh.
screen is also a virtual console multiplyer, that is, you can open multiple consoles with one ssh session and switch between them very quickly. In addition these session can be accessed by other people in parallel and a console can be shared between multiple people.
When you opened with 'screen' a new session you can use various 'screen commands'. Useful commands.
- Create a new additional session CTRL-a c
- Swtch screens and select them CTRL-a n and CTRL-a p, CTRL-a 0, CTRL-a 1 etc, CTRL-A "
- Terminate screens CTRL-a k
- Detach screens , which means a session is ended but continues to run in the backgroud CTRL-a d
- Enable a screen protocol to log which commands you execute on a remote system CTRL-a H
- Turn on and off alerts on a console CTRL-a M
screen invocation parameters
| Parameter | Function | Commant |
| Creates a new screen session | no parameter | |
| -ls | lists like ls the existing screen sessions | |
| -x | Opens a screen to an existing session | That way multiple people can share the same screen |
| -r | Opens a session to a screen session running in the background | Resume a long running session previously opened and then detached |
| -L | Turn on logmode |
Shortcuts in screen windows
CTRL-a just means to press the ctrl and key a together followed by the screen command key.
| Befehl | Funktion | Kommentar |
| CTRL-a " | Show all screen sessions | |
| CTRL-a A | Give a screen window a name (Display and select with C-a ") | |
| CTRL-a 0 | Display screen no 0 | 0-9 possible |
| CTRL-a A | Change window name | |
| CTRL-a c | Create new screen (c = create) | |
| CTRL-a d | Detach a screen and keep it running in the background (d = detach) | |
| CTRL-a k | Terminate screen session (k = kill) | |
| CTRL-a H | Trun screen hardcopy on/off | |
| CTRL-a n | Open next screen (n = next) | |
| CTRL-a p | Open previous screen (p = previous) | |
| CTRL-a ? | Show keybindings (short help text) | |
| CTRL-a * | Display active screen session names at the top of the window |

