Star InactiveStar InactiveStar InactiveStar InactiveStar Inactive
 
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:
  1. 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.
  2. 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.
  3. 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>
  4. 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.
  1. Create a new additional session CTRL-a c
  2. Swtch screens and select them CTRL-a n and CTRL-a p, CTRL-a 0, CTRL-a 1 etc, CTRL-A "
  3. Terminate screens  CTRL-a k
  4. Detach screens , which means a session is ended but continues to run in the backgroud CTRL-a d
  5. Enable a screen protocol to log which commands you execute on a remote system CTRL-a H
  6. Turn on and off alerts on a console CTRL-a M
Every screen command has to ne started with ctrl a and the next keys define the screen command to execute. The following table lists commands I find useful. There are much more which can be found with man screen or just google for screen linux.  CTRL-a ? opens a short help window in screen which lists all commands.
 

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  
 
Add comment

*** Note ***

Comments are welcome. But in order to reject spam posts please consider following rules:
  1. Comments with string http are rejected with message You have no rights to use this tag
  2. All comments are reviewed by hand and thus it usually takes one day until a comment will be published.