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 C-a c and scroll between the screens with C-a n and C-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 C-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 C-a c and jump between the screens with C-a n and C-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 C-a c
- Swtch screens and select them C-a n and C-a p, C-a 0, C-a 1 etc, C-A "
- Terminate screens C-a k
- Detach screens , which means a session is ended but continues to run in the backgroud C-a d
- Enable a screen protocol to log which commands you execute on a remote system C-a H
- Turn on and off alerts on a console C-a M
screen invocation parameters
|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||Einschalten des LogModus|
Shortcuts in screen windows
C-a just means to press the ctrl and a key together
|C-a "||Show all screen sessions|
|C-a A||Give a screen window a name (Display and select with C-a ")|
|C-a 0||Display screen no 0||0-9 possible|
|C-a A||Change window name|
|C-a c||Create new screen (c = create)|
|C-a d||Detach a screen and keep it running in the background (d = detach)|
|C-a k||Terminate screen session (k = kill)|
|C-a H||Trun screen hardcopy on/off|
|C-a n||Open next screen (n = next)|
|C-a p||Open previous screen (p = previous)|
|C-a ?||Show keybindings (short help text)|
|C-a *||Display active screen session names at the top of the window|