2476
Comment:
|
4918
fix
|
Deletions are marked like this. | Additions are marked like this. |
Line 4: | Line 4: |
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 reading the man-page for irssi or something like that. Another great thing with irssi 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! However, since screen is so powerful and flexible, and it's all text-only, it can be hard to understand how everything works and get a good overview. It's also easy to start too many screen sessions, and this way locking yourself out from the shell (since you can only have so many processes/connections). If this happens, talk to Independence and he can help you out. 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. |
Line 7: | Line 11: |
You can detach a screen when you want to log out, this way your programs will keep running while you are away. If you want to be able to do this, you first have to start your programs ''in'' a screen, otherwise you won't be able to detach. |
|
Line 11: | Line 18: |
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 won't see much of any output at all, the only thing that happens (for me atleast) is that the console gets cleared of text. It should look just like a regular login, but this time it is running inside a screen. Now you can just start the program you want, for example irssi. When you want to log out, you can detach your program by entering the key combination of Ctrl-A, D (that is Ctrl-A followed by a D (while still holding down Ctrl)). Now your command is running in the background, inside your screen. You can at this time log out, and come back at a later time to resume your screen, and it will keep running at the server the whole time. To bring the command to the foreground again (reattach the screen), type: |
Line 15: | Line 31: |
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! |
|
Line 16: | Line 35: |
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: | |
Line 18: | Line 36: |
{{{ 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: |
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). |
Line 23: | Line 38: |
{{{ 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. |
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 crate too many, you won't be able to log back in again. Two windows is probably good for most. To switch between two windows inside a screen, press Ctrl-A A. This immediately switches back and forth between two different windows (really, it switches to the last used window). If you have more that two windows, you can use 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 want to see a list of all the windows for a better overview, press Ctrl-A ". You can then select a window with the arrow keys and enter it by pressing enter. If you have more than two windows, it might also be a good idea to name them so you can distinguish them in the list (instead of all being named "bash"). You can do this by pressing Ctrl-A A. |
Line 28: | Line 49: |
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 from a window, 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 54: |
and you will be left back at where you launched or reattached the screen from. | |
Line 36: | Line 57: |
== Extra == If you somehow started two independent screen sessions (not windows, but alltogether different 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>''. If you don't need more than one screen (which you probably don't), you can just resume the one you don't need type ''exit'' or ''logout'' to destroy it. Sometimes when the server reboots, your screens "dies". If this happens, you won't be able to reattach them. Instead, you have to clear the old (by doing ''screen -wipe'') one and start a new. More info: ["FAQ/DeadScreen"]. |
|
Line 38: | Line 65: |
CategoryHowto |
* [http://gentoo-wiki.com/TIP_Using_screen Gentoo Wiki: Using Screen] - More advanced screen usage. Incuding split window into regions etc. ---- . 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 reading the man-page for irssi or something like that.
Another great thing with irssi 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!
However, since screen is so powerful and flexible, and it's all text-only, it can be hard to understand how everything works and get a good overview. It's also easy to start too many screen sessions, and this way locking yourself out from the shell (since you can only have so many processes/connections). If this happens, talk to Independence and he can help you out. 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.
Starting, detaching and reattaching a screen session
You can detach a screen when you want to log out, this way your programs will keep running while you are away. If you want to be able to do this, you first have to start your programs in a screen, otherwise you won't be able to detach.
To start a screen session, simply type:
screen
This will spawn a new screen for you. You won't see much of any output at all, the only thing that happens (for me atleast) is that the console gets cleared of text. It should look just like a regular login, but this time it is running inside a screen.
Now you can just start the program you want, for example irssi.
When you want to log out, you can detach your program by entering the key combination of Ctrl-A, D (that is Ctrl-A followed by a D (while still holding down Ctrl)). Now your command is running in the background, inside your screen.
You can at this time log out, and come back at a later time to resume your screen, and it will keep running at the server the whole time.
To bring the command to the foreground again (reattach the screen), type:
screen -r
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!
The next step
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 crate too many, you won't be able to log back in again. Two windows is probably good for most.
To switch between two windows inside a screen, press Ctrl-A A. This immediately switches back and forth between two different windows (really, it switches to the last used window). If you have more that two windows, you can use 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 want to see a list of all the windows for a better overview, press Ctrl-A ". You can then select a window with the arrow keys and enter it by pressing enter.
If you have more than two windows, it might also be a good idea to name them so you can distinguish them in the list (instead of all being named "bash"). You can do this by pressing Ctrl-A A.
Exiting
To exit from a window, 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]
Have fun!
Extra
If you somehow started two independent screen sessions (not windows, but alltogether different 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>. If you don't need more than one screen (which you probably don't), you can just resume the one you don't need type exit or logout to destroy it.
Sometimes when the server reboots, your screens "dies". If this happens, you won't be able to reattach them. Instead, you have to clear the old (by doing screen -wipe) one and start a new. More info: ["FAQ/DeadScreen"].
More
- ["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.