Difference between revisions of "Tutorials and How-tos/GNU Screen Quick Tutorial"

From BubbaWiki
Jump to navigation Jump to search
 
Line 53: Line 53:
   '''Ctrl+a d''' command (press and hold '''Ctrl''', press and hold '''a''', then press '''d''') to detach from the session.  
   '''Ctrl+a d''' command (press and hold '''Ctrl''', press and hold '''a''', then press '''d''') to detach from the session.  


The following key-combinations can be used, when a screen is running, and is attached to the consol. All key kombinations begin with pressing control and a simultaniusly.
The following key-combinations can be used, when a screen is running, and is attached to the consol. All key kombinations begin with pressing control and a simultaniusly.  


Code: Select all<br> ctrl+a d - detach the screen, and let it run without user interface (as described above)<br>ctrl+a c - create a new terminal<br> ctrl+a A - set the name of the current terminal<br> ctrl+a n - switch to next terminal<br> ctrl+a p - switch to prev terminal<br> ctrl+a " - list the of terminals<br>
Code: Select all<br> ctrl+a d - detach the screen, and let it run without user interface (as described above)<br>ctrl+a c - create a new terminal<br> ctrl+a A - set the name of the current terminal<br> ctrl+a n - switch to next terminal<br> ctrl+a p - switch to prev terminal<br> ctrl+a " - list the of terminals<br>  


== How to List all Screen sessions  ==
== How to List all Screen sessions  ==
Line 70: Line 70:
  $ '''screen -list'''
  $ '''screen -list'''
  Your inventory:
  Your inventory:
  4087.radio      (Detached)
4087.radio      (Detached)
  13294.backup    (Detached)
13294.backup    (Detached)


<br>  
<br>  
Line 90: Line 90:


You can switch between sessions using ''Ctrl+a n'' command (to switch to the next session) or ''Ctr+a 0...9'' (to switch to a specific session).
You can switch between sessions using ''Ctrl+a n'' command (to switch to the next session) or ''Ctr+a 0...9'' (to switch to a specific session).
== Further reading ==
Gentoo screen wiki:
http://gentoo-wiki.com/TIP_Using_screen

Latest revision as of 02:26, 24 November 2010

What is Screen?

This nifty utility allows you to access multiple separate terminal sessions inside a single terminal window or remote terminal session.


Why is screen useful?

When you establish a connection from the terminal, the session will remain active only as long as you keep the terminal window open. If you close it, the session terminates along with all the active processes.

This means, for example, that if you want to run a backup script on the server, you must keep the terminal window open till the script is done. This is not always practical, especially if the backup operation takes a long time to complete.

This is where the GNU Screen comes into the picture. Using it, you can create a session that will keep running even if you close the terminal window.


How to install screen

1. Access your bubba via SSH (see Howto/Access Server via SSH for information how to accomplish this) Change to the user root: (By default: When asked for password, type excito and press enter)

$ su

2. Install the application:

$ apt-get install screen


How to start a new Screen

To start an unnamed screen.

$ screen

To create a new session with a specific name (eg: backup or perhaps rTorrent) use:

$ screen -S backup

 -these both commands create a new persistent session, and you can use it as a regular terminal window, i.e., issue commands and run scripts.

To see the list of runnging screens:

$ screen -ls 

To attach a running screen to the consol:

$ screen -R

Screen commands

If you want to leave the session without terminating it, use:

 Ctrl+a d command (press and hold Ctrl, press and hold a, then press d) to detach from the session. 

The following key-combinations can be used, when a screen is running, and is attached to the consol. All key kombinations begin with pressing control and a simultaniusly.

Code: Select all
ctrl+a d - detach the screen, and let it run without user interface (as described above)
ctrl+a c - create a new terminal
ctrl+a A - set the name of the current terminal
ctrl+a n - switch to next terminal
ctrl+a p - switch to prev terminal
ctrl+a " - list the of terminals

How to List all Screen sessions

To re-connect to the session, use screen -r. If multiple sessions are running you get a listing of the screens:

 $ screen -r 
There are several suitable screens on:
4870.pts-4.localhost (Detached)
4638.pts-1.localhost (Detached) 

Another way to list the screens active is to use the screen -list command:

$ screen -list
Your inventory:
4087.radio      (Detached)
13294.backup    (Detached)


How to attach to a Screen session

To re-attach to, for example, the first session in the list, use the screen -r command as follows:

 $ screen -r 4870.pts-4.localhost

Or you can to reattach to the 'backup' screen (as long as there is only 1 screen with that name running) you can just use:

 $ screen -r backup


Switching between sessions

You can switch between sessions using Ctrl+a n command (to switch to the next session) or Ctr+a 0...9 (to switch to a specific session).


Further reading

Gentoo screen wiki: http://gentoo-wiki.com/TIP_Using_screen