Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

Screen.md 10 KiB

3 år sedan
4 år sedan
3 år sedan
4 år sedan
3 år sedan
4 år sedan
3 år sedan
4 år sedan
3 år sedan
4 år sedan
3 år sedan
4 år sedan
3 år sedan
4 år sedan
3 år sedan
4 år sedan
3 år sedan
4 år sedan
3 år sedan
4 år sedan
3 år sedan
4 år sedan
3 år sedan
4 år sedan
3 år sedan
4 år sedan
3 år sedan
4 år sedan
3 år sedan
4 år sedan
3 år sedan
4 år sedan
3 år sedan
4 år sedan
3 år sedan
4 år sedan
3 år sedan
4 år sedan
3 år sedan
4 år sedan
3 år sedan
4 år sedan
3 år sedan
4 år sedan
3 år sedan
4 år sedan
3 år sedan
4 år sedan
3 år sedan
4 år sedan
3 år sedan
4 år sedan
3 år sedan
4 år sedan
3 år sedan
4 år sedan
3 år sedan
4 år sedan
3 år sedan
4 år sedan
3 år sedan
4 år sedan
3 år sedan
4 år sedan
3 år sedan
4 år sedan
3 år sedan
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317
  1. ## Basics
  2. **Screen** usually does not exist; this <s>is the committee\'s</s> was a
  3. former committee\'s general position on screen due to the disastrous
  4. and/or hilarious situations which often result from new members\'
  5. attempts to get it working. However, for the purpose of this tutorial,
  6. screen **does** exist, and this is how you use it. (Blame coconut for
  7. this defiance.)
  8. ### Omg, what\'s screen?
  9. Screen is most commonly known as \"that thing that lets you stay logged
  10. in to chat when you log out of RedBrick\". It\'s a terminal multiplexer,
  11. which allows you to log into multiple terminal sessions from one
  12. terminal window and keeps them open when you go away to bed or whatever
  13. it is you do with your time.
  14. ### Opening
  15. Type \"screen\" at the prompt like this:
  16. [Image:screen1.jpg](/Image:screen1.jpg "wikilink")
  17. This will open a new screen session. First you\'ll see the screen
  18. startup message, which gives a little info on the program.
  19. [Image:screen2.jpg](/Image:screen2.jpg "wikilink")
  20. Just hit space/return as it says and you\'ll be running screen. You
  21. won\'t notice anything immediately different once running screen,
  22. instead, you\'ll be back at the same old terminal. Now, however, you
  23. have access to a large variety of commands and features that you didn\'t
  24. before.
  25. ## Screen commands
  26. ### Ctrl-a commands
  27. Nearly all of screen\'s commands are used via the ctrl-a key
  28. combination. First, you press the ctrl and a keys together, then
  29. release. Next, press the key you want to run a command. These commands
  30. can be a little awkward and difficult to remember at first, but you\'ll
  31. soon get the hang of it. In this tutorial, the commands will be shown as
  32. ctrl-a and then a letter, with the following letter being associated
  33. with a command.
  34. ### Creating a new window
  35. When you start screen, it presents you with the normal single window
  36. terminal you\'re used to. You can, however, create many more and run
  37. them all within the one screen session. The following command will
  38. create another window for you:
  39. `ctrl-a c`
  40. Just hit ctrl and a together, then release them and hit c. This
  41. keybinding will open a new window (window 2) inside screen. Now you\'ll
  42. have two windows to use, so you\'ll have to learn how to use the ctrl-a
  43. commands to switch between them.
  44. ### Switching windows
  45. Once you have more than one window open, you can switch between them
  46. using some of the following commands:
  47. `ctrl-a n`
  48. This command will switch you over to the next window.
  49. `ctrl-a p`
  50. This one will bring you back to the previous window.
  51. `ctrl-a a`
  52. This will switch between the last two windows that you\'ve been using.
  53. `ctrl-a window_number`
  54. Using this command, you can specify exactly which window you want to
  55. jump to by hitting ctrl and a, then the number on the keyboard of your
  56. desired window. This is pretty useful for when you have a lot of windows
  57. open in screen.
  58. ### Naming your windows
  59. You can give each of your windows its own name too for convenience by
  60. using this command:
  61. `ctrl-a A`
  62. This one might seem confusing first as the A is a capital letter in this
  63. case, but all you need to do is hit ctrl and a together and release as
  64. before, then hold shift and press a to get the capital. After you run
  65. it, you\'ll see a white bar appear at the bottom of your window, where
  66. you can change the name of your screen to whatever you like. In this
  67. case, the window has just been renamed to \"chat\".
  68. [Image:screen3.jpg](/Image:screen3.jpg "wikilink")
  69. After you\'ve named a few windows, you can try this command:
  70. `ctrl-a "`
  71. Yup, even quotation marks can be used in screen commands. So as before
  72. you do ctrl-a, then hold shift and hit the 2 key to get the \" :) This
  73. will bring up a convenient list of all your windows with their names.
  74. [Image:screen4.jpg](/Image:screen4.jpg "wikilink")
  75. From this window you can view and go to any of your windows. The flags
  76. on the right indicate whether your window is logged in or not with \$
  77. symbol.
  78. ### Detaching and reattaching screen
  79. One of the most popular features of screen is that it can keep you
  80. logged in even when you\'re offline. This means you can leave programs
  81. running or even stay on IRC even when you\'re not online. When you
  82. \"minimise\" screen or make it invisible, it is called detaching it.
  83. To do this, you just detach from screen instead of exiting it. To detach
  84. from screen without exiting, use the following command:
  85. `ctrl-a d`
  86. You\'ll then be returned to the prompt with a message telling you screen
  87. has been detached, like so:
  88. [Image:screen5.jpg](/Image:screen5.jpg "wikilink")
  89. Later, you\'ll come back online and want to reattach to your screen
  90. session. When you \"maximise\" screen or bring it back onto your
  91. terminal, this is known as attaching. To reattach a detached screen, use
  92. this command at the prompt:
  93. `screen -dr`
  94. The -d will detach any attached screens and -r will reattach your
  95. screen.
  96. If you have more than one screen session available, you will need to
  97. specify the screen id you wish to open. You\'ll be given a list of the
  98. currently available screens, so then you type:
  99. `screen -r`
  100. followed by the id listed above of the screen you want to reattach to.
  101. ### Moving windows
  102. If are in a window, but want it to move it to another, just type these
  103. commands while attached to screen and in that window, and replace **x**
  104. with the destination you want:
  105. `Ctrl + a`\
  106. `:`\
  107. `number x`
  108. For example, if you are in window number 2, press **Ctrl+a**, then type
  109. the colon symbol (**:**), then **number 4**, to move that window to
  110. window 4.
  111. ### Start and stop signals
  112. Quite often it happens someone may end up using the stop signal command
  113. in screen by mistake. This command is:
  114. `ctrl-a s`
  115. and you should probably avoid using it! But as the s key is beside the a
  116. key, people will occasionally run this command by accident without
  117. knowing it. As this is a stop signal, it has the unfortunate side effect
  118. of freezing up your window :( Worry not however, for to fix it, all you
  119. need to do is use the start signal again to bring it back from the dead:
  120. `ctrl-a q`
  121. This should have you back in action very shortly. However, if your
  122. screen is frozen and you can\'t figure out why, try asking a member of
  123. [Helpdesk](/Helpdesk "wikilink") and they should know the answer :)
  124. ### Killing screen while attached
  125. Often enough new members (and often, experienced people) will make
  126. mistakes with screen that they can\'t fix. To kill screen altogether and
  127. start over, use:
  128. `ctrl-a \`
  129. Or, if you just want to kill a single window in screen, use:
  130. `ctrl-a k`
  131. or even just type \"exit\" at the prompt.
  132. ### Killing screen while detached
  133. **Warning**: using the _kill_ command to do anything can be very
  134. dangerous if you don\'t know what you\'re doing. If you\'re unsure,
  135. reattach the screen you want to kill and follow the instructions above.
  136. If you have more than one screen session and you want to kill one of
  137. them, type \"screen -dr\" to get a list of the available screens (from
  138. the terminal which appears when you first log in to RedBrick). Note the
  139. **number** (also known as a process id, or pid) at the beginning of each
  140. screen name. This is the process number. Ensure you know which screen
  141. session is which.
  142. To terminate a session, use this command (_pid_ is the number of the
  143. session you want to kill)
  144. `kill`_`pid`_
  145. This will send the signal SIGTERM to the process, requesting its
  146. termination.
  147. If that fails and you want lil_cain to start complaining
  148. `kill -9`_`pid`_
  149. This will send the signal SIGKILL to the process, terminating it
  150. immediately and with lots of blood.
  151. Then, to then get rid of the dead screen session, type
  152. `screen -wipe`
  153. ## Screen Configuration
  154. So after you\'ve set up screen and have gotten used to it, you will
  155. probably want to configure it a little bit and the way to do this is by
  156. creating a \~/.screenrc
  157. To do this just
  158. `nano ~/.screenrc`
  159. Here\'s an example of a .screenrc that you may want to use:
  160. `hardstatus alwayslastline`\
  161. `hardstatus string '%{= kg}[ %{G}%H %{g}][%= %{= kw}%?%-Lw%?%{=b kR}(%{W}%n*%f %t%?(%u)%?%{=b kR})%{= kw}%?%+Lw%? %?%= %{g}][%{Y}%l%{g}]%{=b C}[ %d %M %c ]%{W}'`\
  162. `deflogin off`\
  163. `startup_message off`\
  164. `screen -t irc 1 irssi`\
  165. `screen -t Email/slrn 2 mutt -Z`\
  166. `screen -t heys -L -l 3`
  167. Basically this only really does two things, sets a hardstatus (basically
  168. a line that contains some information) and makes it display only on the
  169. bottom line and also creates a few new windows.
  170. The new windows created are given names and optionally a number or
  171. command (or both).
  172. `screen -t irc q irssi`
  173. This will create screen window 1, give it the title \"irc\" and then run
  174. irssi when you start screen.
  175. `deflogin off`
  176. This sets windows logged out by default, which means that you won\'t
  177. have to \"mesg n\" windows to not receive heys
  178. `startup_message off`
  179. This turns the startup message thats displayed when you start a new
  180. screen session off.
  181. `screen -t heys -L -l 3`
  182. Will create a logged in window specifically for heys. Handy.
  183. All this makes it very simple to restart all your processes if Redbrick
  184. ever crashes.
  185. With the above configuration file it will look something like this:
  186. [Image:screenrc.jpg](/Image:screenrc.jpg "wikilink")
  187. ### Reattaching Screen Automatically
  188. So, you\'ve made your screen, configured it, and you happily type screen
  189. -dr **every time** you login to RedBrick. But wouldn\'t it be nice if
  190. whenever you login your screen would reattach **itself**??? It can be
  191. done :D
  192. Simply use your favorite text editor to edit your \~/.zlogin if you\'re
  193. using zsh (if you haven\'t changed your login shell, this is the one
  194. you\'re using) or \~/.bash_login if you\'re using bash and put the
  195. following in it
  196. `screen -dr`
  197. That should do the job. It\'ll try to reattach a screen whenever you
  198. login on any redbrick server
  199. * Please note, if this in fact, does not work, you can edit it out by
  200. using winSCP and editing the file using it.
  201. ## Useful links
  202. If you\'d like to learn more about the program, a long list of screen
  203. commands can be found here:
  204. <http://www.linuxdevcenter.com/linux/cmd/cmd.csp?path=s/screen>
  205. Help edited a screenrc:
  206. <http://www.debian-administration.org/articles/560>
  207. A starting guide to screen:
  208. <http://magazine.redhat.com/2007/09/27/a-guide-to-gnu-screen/>
  209. The Gentoo wiki article on screen (quite in depth) :
  210. <http://www.gentoo-wiki.info/Screen>
  211. [Category:Helpdesk](/Category:Helpdesk "wikilink")