This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revision | |||
| tutorials:screen [2012/05/01 15:18] – Everything OK!! ivan | tutorials:screen [2012/05/08 15:08] (current) – $ID memnon | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| + | ===== GNU Screen ===== | ||
| + | * [[# | ||
| + | * [[#Starting Screen, detaching and reattaching]] | ||
| + | * [[#Multiple windows]] | ||
| + | * [[#Multiple sessions]] | ||
| + | * [[# | ||
| + | * [[#Sharing screen sessions]] | ||
| + | * [[# | ||
| + | * [[#Cheat sheet]] | ||
| + | * [[# | ||
| + | |||
| + | ==== Introduction ==== | ||
| + | |||
| + | [[http:// | ||
| + | //terminal multiplexer//, | ||
| + | terminals in a single window. You will also be able to 1) //detach// a | ||
| + | screen session, and then detach it in a later moment; 2) share screen | ||
| + | sessions. | ||
| + | |||
| + | In this tutorial "> | ||
| + | |||
| + | A Screen command is usually of the form //CTRL-a KEY//, | ||
| + | i.e., you'll have to press the //CTRL// key along with // | ||
| + | followed by a generic KEY. (Screen' | ||
| + | //CTRL-a//) | ||
| + | |||
| + | You'll need to be a [[http:// | ||
| + | in order to use Screen on SDF | ||
| + | |||
| + | If you want a // | ||
| + | >$ ttyplay / | ||
| + | |||
| + | on a terminal connected to SDF. | ||
| + | |||
| + | Alternatively, | ||
| + | online at [[http:// | ||
| + | |||
| + | ==== Starting Screen, detaching and reattaching ==== | ||
| + | |||
| + | You can run screen by typing: | ||
| + | |||
| + | >$ screen | ||
| + | |||
| + | When you run it, a window with some copyright and some other info will show | ||
| + | up, with //[Press Space or Return to end.]// at the bottom. OK, as it | ||
| + | says, you can now press //Space// or //Enter//. You will then see your | ||
| + | shell prompt and nothing else. That's fine: you can now run your programs as | ||
| + | usual, the difference is that they will run under a Screen session. | ||
| + | You can //detach// it by typing //CTRL-a d//. Screen will keep | ||
| + | your session running. Now if you logout, then log back in, and type: | ||
| + | |||
| + | >$ screen -r | ||
| + | |||
| + | you'll see your terminal as you left it when you detached Screen! | ||
| + | |||
| + | If you lost connection, or simply forgot to detach Screen, and want to resume your session | ||
| + | by typing: | ||
| + | |||
| + | >$ screen -d -r</ | ||
| + | |||
| + | The //-d// flag will detach Screen, while //-r// will reattach. There | ||
| + | are various types of //detach// and // | ||
| + | if you type the previous command and there was no screen session to be | ||
| + | resumed, you'll get a //There is no screen to be detached.// message. In | ||
| + | this case you'll probably need: | ||
| + | |||
| + | >$ screen -d -R | ||
| + | |||
| + | which will first create a new session (or rettach an existing one). | ||
| + | |||
| + | ==== Multiple windows ==== | ||
| + | |||
| + | You can create various windows under your Screen session, each one running | ||
| + | their own program. When you are in a Screen session, typing: | ||
| + | |||
| + | >$ screen | ||
| + | |||
| + | will create a new window, leaving the previous window untouched, though not | ||
| + | visible. Instead of typing //screen//, you can use the shortcut //CTRL-a c//. | ||
| + | |||
| + | You can create as many windows as you want. You can swith between windows | ||
| + | with //CTRL-a n// (next window) and //CTRL-a p// (previous window). It's also possible to select | ||
| + | windows by number. Typing //CTRL-a 1// will open window | ||
| + | number 1, //CTRL-a 2//, to window 2, and so on. | ||
| + | |||
| + | How do you know what's a window number? Well, you can type | ||
| + | //CTRL-a "// (yeah, that's a double quote). In that case a menu | ||
| + | with a windows list will open. You can select a number and press enter to go | ||
| + | to that screen. An easier way is to have a //hard status line// that | ||
| + | shows you each window number. For doing this in a permanent manner, you'll | ||
| + | have to create a // | ||
| + | $HOME directory and write in it the following lines: | ||
| + | |||
| + | hardstatus alwayslastline | ||
| + | hardstatus string " | ||
| + | |||
| + | (We will see what that crazyness means later.) | ||
| + | |||
| + | For your .screenrc file to be read by Screen, you'll have to start a new | ||
| + | session. BTW, a Screen session ends when the last window is closed. | ||
| + | |||
| + | ==== Multiple sessions ==== | ||
| + | |||
| + | It's possible to have various Screen sessions running, each one with their | ||
| + | own set of windows open. If you started Screen by just typing //screen//, | ||
| + | a new session is created. If you detach and type //screen// again, a new | ||
| + | session will start. If you now type: | ||
| + | |||
| + | >$ screen -ls | ||
| + | |||
| + | it will give you a list of Screen sessions like this: | ||
| + | |||
| + | |||
| + | 3340.pts-6.HOST | ||
| + | 4522.pts-8.HOST | ||
| + | 2 Sockets in / | ||
| + | |||
| + | where HOST is the hostname and YOU is your username. | ||
| + | |||
| + | You can reattach a screen session by name. Say for instance that you want to | ||
| + | resume the // | ||
| + | |||
| + | >$ screen -r 4522.pts-8.HOST | ||
| + | |||
| + | Obviously // | ||
| + | You can give a meaningful name by starting screen as: | ||
| + | |||
| + | >$ screen -S mysession | ||
| + | |||
| + | where // | ||
| + | //work//). | ||
| + | |||
| + | ==== Splitting windows ==== | ||
| + | |||
| + | It could be useful to split a window so that you can have two programs | ||
| + | running on the viewport. In this case, type //CTRL-a S// and you'll see that | ||
| + | the window will be split in two regions, with | ||
| + | the one at the bottom blank. You can swith to it with | ||
| + | //CTRL-a TAB// (TAB is the tab key) and then select a window | ||
| + | by typing its number, or //p// (previous) or //n// (next), e.g., | ||
| + | //CTRL-a 2//. You can always swith through regions with //CTRL-a TAB//. | ||
| + | |||
| + | It's possible to split the window in more then two regions, each time by | ||
| + | typing //CTRL-a S// | ||
| + | |||
| + | If you want to split a window vertically, you'll have to either use a | ||
| + | patch[1] or use a recent version of Screen. | ||
| + | |||
| + | ==== Sharing screen sessions ==== | ||
| + | |||
| + | The scenario is... | ||
| + | '' | ||
| + | '' | ||
| + | '' | ||
| + | Only three commands are needed for basic read only access to the current active window. | ||
| + | |||
| + | '' | ||
| + | CTRL-a: | ||
| + | CTRL-a: | ||
| + | CTRL-a: | ||
| + | '' | ||
| + | >$ screen -r HOSTUSER/ | ||
| + | |||
| + | '' | ||
| + | |||
| + | '' | ||
| + | //CTRL-a*// | ||
| + | '' | ||
| + | // | ||
| + | |||
| + | '' | ||
| + | //CTRL-a*// | ||
| + | |||
| + | '' | ||
| + | The following commands allow '' | ||
| + | '' | ||
| + | // | ||
| + | // | ||
| + | // | ||
| + | |||
| + | === Some notes:=== | ||
| + | - Screen version that was used " | ||
| + | - At the time of writing ( Tue Apr 17 23:01:50 IST 2012 ) all attempts at achieving the above read only functionality by editing .screenrc failed, usually resulting in SOMEUSER having FULL access to HOSTUSER' | ||
| + | - '' | ||
| + | - After '' | ||
| + | - For convenience and to reduce typing in screen '' | ||
| + | - '' | ||
| + | - '' | ||
| + | - '' | ||
| + | - '' | ||
| + | |||
| + | ==== .screenrc ==== | ||
| + | |||
| + | As we previously saw, it is possible to customize Screen by writing settings | ||
| + | in a file named // | ||
| + | useful Screen settings. | ||
| + | |||
| + | === Avoiding the startup message == | ||
| + | |||
| + | A full screen message with copyright and other stuff is usually displayed at | ||
| + | startup. This can get annoying. In order to avoid it, you can put in | ||
| + | your .screenrc the following: | ||
| + | |||
| + | startup_message off | ||
| + | |||
| + | === Keybindings === | ||
| + | |||
| + | It's possible to bind keys so that when you type //CTRL-a KEY// | ||
| + | Screen willl open a new window launching some | ||
| + | program. For instance, if you write in your .screenrc file | ||
| + | |||
| + | bind m screen -t mail 1 mutt | ||
| + | |||
| + | each time you'll type //CTRL-a m// a new window (named | ||
| + | //mail//) with mutt will be created. Be careful: when you bind a key, | ||
| + | you'll overwrite Screen' | ||
| + | key). | ||
| + | |||
| + | ===== Cheat sheet ====== | ||
| + | |||
| + | TODO | ||
| + | |||
| + | ==== Resources ==== | ||
| + | |||
| + | * http:// | ||
| + | * http:// | ||
| + | * SDF has some [[http:// | ||
| + | |||
| + | ==== Notes ==== | ||
| + | |||
| + | - http:// | ||
| + | |||
| + | $Id: screen.html, | ||