2476
Comment:
|
5680
changed the order of some stuff
|
Deletions are marked like this. | Additions are marked like this. |
Line 1: | Line 1: |
#pragma keywords screen, gnu screen, irssi, howto, tutorial, detach | |
Line 4: | Line 5: |
For example, if you wish to run a command that will take time to finish, but at the same time you don't want to open more connections to your shell to do other things while the first command is running. Screen to the rescue. | For example, if you wish to run two programs at the same time, without having to open multiple connections to the server, you can do this with screen. Maybe you want to run irssi, while at the same time checking your E-mail. |
Line 6: | Line 7: |
== Starting, detaching and reattaching a screen session == To start a screen session, simply type: |
Another great thing with Screen is that it allows you to keep your programs running while you are disconnected from the server. This makes it possible to stay connected to IRC and log everything even while your computer is turned off! All you have to do is start your IRC client in a Screen and then "detach" when you go offline. However, since screen is very powerful and flexible, and it's all text-only, it can be hard to understand how to use it properly. It's also easy to start too many screens and lock yourself out of the system (since you can only have so many logins/processes). If this happens, talk to an admin to get help exiting your processes. Also remember that you are only allowed to run two programs in the background, for example one instance of irssi and one instance of lynx. Also, it's not ok to run multiple instances of irssi. == Screen basics == If you want to run a program on the server even while you are not connected, you first have to start the program inside a Screen. You can then detach this screen, and attach it another time (from another computer maybe). To start a new screen, use the command screen in an empty shell on the server: |
Line 11: | Line 19: |
This will spawn a new screen for you, and you should notice.. nothing at all. It should look like a regular login, but this time it is running inside a screen. Start your command, and let us say that you wish to go back to the console you launched screen from. To do this, simply enter the key combination of Ctrl-A, D (that is Ctrl-A followed by a D). Now your command is running in the background, inside your screen. To bring the running command to the foreground again (reattach), type: | This will spawn a new screen for you. You will get a new empty shell, and at the bottom you can see a status bar, called a hardstatus line. In this hardstatus line you can see the different "windows" you have running in this screen session. Now you can now start whatever program you would like to run. When you want to log out, you can detach your program by entering the key combination of Ctrl-a d (that is; press Ctrl-a and then press d). Now your program is running in the detached screen, waiting for you to return and attach the screen session again. You can now log out from the shell, and the screen session will still be there when you log back in (unless the server reboots). To attach your screen session again, use this command in an empty prompt: |
Line 15: | Line 32: |
== The next step == To make things a bit easier there is a few hints. If you want to run multiple commands at the same time and still be able to have a free console, you can do it in a few ways. You could detach from the running screen and create a new one from which you launch your second command. If you opt for doing things this way, you want to start your screens with the -S flag and a name for your screen, like this: |
Remember to not start mulitple screens, it will only make things harder for you. If you want to list your running screens, you can use this command: |
Line 19: | Line 38: |
screen -S emacs }}} This will create a new screen with the name emacs. If you have several screens running in paralell, naming them will make your life a whole lot easier. To reattach a particular named screen, run: |
screen -ls}}} |
Line 23: | Line 40: |
{{{ screen -r emacs}}} The other way is to create a new window inside your screen. This is done by the key combination Ctrl-A, C. (C for Create). You should be presented with a brand new window. To step between windows inside your screen, press Ctrl-A, <space> for stepping forward, and Ctrl-A <backspace> for stepping backwards. You may also also use Ctrl-A <0-9> where the number is the window you want to visit. |
If you have multiple screens, resume them one by one and exit. |
Line 27: | Line 42: |
== Exiting == To end your screen session after all your commands has finished, simply logout or exit from within the screen, as you would do when you exit your regular shell. Screen will say |
To exit just type ''logout'' or ''exit'' (you can also do this by pressing Ctrl-d). If you only have one window, you will exit the screen session and you will get a message like this: |
Line 32: | Line 46: |
and you will be left back at where you launched or reattached the screen from. | |
Line 34: | Line 47: |
Have fun! | That wasn't too hard, was it? :) Whith the few things you have learned this far, you can really make so much more of your shell experience. It's a truly great tool! == Good to know == If your connection to the shell is lost, you might not be able to resume your screen right away because the server thinks it's still in use until a timeout is reached. If you want to resume right away, you can use this command: {{{ screen -rd}}} This command will detach any previously attached clients and then attach you. If you somehow started two alltogether different screen sessions you might not be able to resume the right one just by tying ''screen -r''. In this case, you have to specify ''screen -r <id>''. You can get a list of current running screen sessions and their id with the command ''screen -ls''. Just resume any extra screens you don't need and exit them by typing ''exit'', ''logout'' or Ctrl-d. Sometimes when the server reboots, your screens "dies". If this happens, you won't be able to reattach it. Instead, you have to clear the old one by doing ''screen -wipe'' and start a new one. [[FAQ/DeadScreen]] == Multiple windows == Now, if you want to run multiple programs at the same time, and easily switch between them, you can create several "windows" in your screen session. To create a new window, use this key combination: Ctrl-a c (c for Create). You should be presented with a brand new prompt, where you can start yet another program. You can create even more windows if you want, but be careful not to start any more than you need. If you create too many, you won't be able to log back in again. Try not to have more than three windows running at the same time. You can see your windows in the hardstatus line at the bottom of your terminal. To exit a window, just exit the shell in that window typing ''logout'' or ''exit''. When you close the last window, the screen will terminate. To switch between two windows inside a screen, press Ctrl-a a. This immediately switches back and forth between two windows (really, it switches to the last used window). If you have more that two windows, you can use Ctrl-a n for stepping forward (next window), and Ctrl-a p for stepping backwards (previous window). You may also also use Ctrl-a <0-9> where the number is the window you want go to. Ctrl-a " gives a list of current windows, and you can select the one you want to go to. |
Line 37: | Line 74: |
* ["FAQ/DeadScreen"] - What to do with "dead screens". CategoryHowto |
* [[FAQ/DeadScreen]] - What to do with "dead screens". * [[http://gentoo-wiki.com/TIP_Using_screen|Gentoo Wiki: Using Screen]] - More advanced screen usage. Incuding split window into regions etc. * [[http://f0rked.com/articles/irssi|A Guide to Efficiently Using Irssi and Screen]] - Screen together with irssi. ---- . CategoryHowto |
Screen
Screen is a great tool which has many uses. You could think about it as a kind of a window manager for your console.
For example, if you wish to run two programs at the same time, without having to open multiple connections to the server, you can do this with screen. Maybe you want to run irssi, while at the same time checking your E-mail.
Another great thing with Screen is that it allows you to keep your programs running while you are disconnected from the server. This makes it possible to stay connected to IRC and log everything even while your computer is turned off! All you have to do is start your IRC client in a Screen and then "detach" when you go offline.
However, since screen is very powerful and flexible, and it's all text-only, it can be hard to understand how to use it properly. It's also easy to start too many screens and lock yourself out of the system (since you can only have so many logins/processes). If this happens, talk to an admin to get help exiting your processes. Also remember that you are only allowed to run two programs in the background, for example one instance of irssi and one instance of lynx. Also, it's not ok to run multiple instances of irssi.
Screen basics
If you want to run a program on the server even while you are not connected, you first have to start the program inside a Screen. You can then detach this screen, and attach it another time (from another computer maybe).
To start a new screen, use the command screen in an empty shell on the server:
screen
This will spawn a new screen for you. You will get a new empty shell, and at the bottom you can see a status bar, called a hardstatus line. In this hardstatus line you can see the different "windows" you have running in this screen session.
Now you can now start whatever program you would like to run.
When you want to log out, you can detach your program by entering the key combination of Ctrl-a d (that is; press Ctrl-a and then press d). Now your program is running in the detached screen, waiting for you to return and attach the screen session again.
You can now log out from the shell, and the screen session will still be there when you log back in (unless the server reboots).
To attach your screen session again, use this command in an empty prompt:
screen -r
Remember to not start mulitple screens, it will only make things harder for you.
If you want to list your running screens, you can use this command:
screen -ls
If you have multiple screens, resume them one by one and exit.
To exit just type logout or exit (you can also do this by pressing Ctrl-d). If you only have one window, you will exit the screen session and you will get a message like this:
[screen is terminating]
That wasn't too hard, was it? Whith the few things you have learned this far, you can really make so much more of your shell experience. It's a truly great tool!
Good to know
If your connection to the shell is lost, you might not be able to resume your screen right away because the server thinks it's still in use until a timeout is reached. If you want to resume right away, you can use this command:
screen -rd
This command will detach any previously attached clients and then attach you.
If you somehow started two alltogether different screen sessions you might not be able to resume the right one just by tying screen -r. In this case, you have to specify screen -r <id>. You can get a list of current running screen sessions and their id with the command screen -ls. Just resume any extra screens you don't need and exit them by typing exit, logout or Ctrl-d.
Sometimes when the server reboots, your screens "dies". If this happens, you won't be able to reattach it. Instead, you have to clear the old one by doing screen -wipe and start a new one. FAQ/DeadScreen
Multiple windows
Now, if you want to run multiple programs at the same time, and easily switch between them, you can create several "windows" in your screen session. To create a new window, use this key combination: Ctrl-a c (c for Create).
You should be presented with a brand new prompt, where you can start yet another program. You can create even more windows if you want, but be careful not to start any more than you need. If you create too many, you won't be able to log back in again. Try not to have more than three windows running at the same time. You can see your windows in the hardstatus line at the bottom of your terminal. To exit a window, just exit the shell in that window typing logout or exit. When you close the last window, the screen will terminate.
To switch between two windows inside a screen, press Ctrl-a a. This immediately switches back and forth between two windows (really, it switches to the last used window). If you have more that two windows, you can use Ctrl-a n for stepping forward (next window), and Ctrl-a p for stepping backwards (previous window).
You may also also use Ctrl-a <0-9> where the number is the window you want go to. Ctrl-a " gives a list of current windows, and you can select the one you want to go to.
More
FAQ/DeadScreen - What to do with "dead screens".
Gentoo Wiki: Using Screen - More advanced screen usage. Incuding split window into regions etc.
A Guide to Efficiently Using Irssi and Screen - Screen together with irssi.