GNU Screen (usually just called screen) is a program that allows the user (ie, you) to command persistent console sessions on a Linux server. This article covers its basic functionality for use on ada, but screen comes packaged with most Linux distros and should work the same.
It's not only useful for keeping you always logged into IRC, but many use it to keep a "virtual workspace" of sorts. Leave your command line programs running at all times, even when you're not logged in. Have one window with irc, another with a file open in vim, another where you're using
wget to download Hackers in 720p. Next time you log in, it'll all be there just like you left it.
Another popular alternative is tmux, but meh.
Easy! Connect to ada with ssh and invoke the
ferris@home-computer:~$ ssh firstname.lastname@example.org Password: . . . Welcome to ADA! buefer21@ada:~$ screen
What happened there? After typing
screen, it looks like nothing's happened. But that's the beauty of screen, baby! It opens a virtual console on ada that'll stay there even after you out log out of ada. There's a lot of key commands to control screen, each starting with ctrl + a held at the same time (henceforth referred to as
C-a) followed by a command.
C-a ? to get all the commands, or just jump to the cheatsheet.
Right now you're "attached" to a screen session you created. If you're on ada then you'll probably have a gray window bar at the bottom, but that's only because ada has a totally sweet screen config by default. Try
C-a d to detach:
C-a d [detached from 24697.pts-12.ada] buefer21@ada:~$
Check it! You've detached from your screen session. Run
screen -dr and...
buefer21@ada:~$ screen -dr
Wham! You're right back in your screen session! And it'll be just how you left it.
- r means reattach to the screen.
- d tells screen to detach the screen if it's attached in another terminal.
- Handy if you might've left yourself attached elsewhere.
Each screen session can have a number of windows to flip between. Try using
C-a c to create a new window, then
C-a A to name it.
C-a n and
C-a p to switch to the next/previous window.
C-a [number] will move you to that particular window number. Or use
C-a a to flip-flop between two windows.
exit in a window to close it, or use
Using with IRC
See also: IRC
Woooo! This is probably why you're here. Using using an IRC client within is handy so you don't have to always be logging in and out, and you'll be able to view the chat history (which you would lose if you weren't in the channel).
The IRC page has details on how to use various clients. Once you learn how to use screen, you can keep a window running an irc client at all times.
buefer21@ada:~$ screen -dr (in a screen session now) buefer21@ada:~$ irssi
Managing multiple sessions
If you have more than one screen session active at once, you'll have to specify which one you want to attach to.
screen -ls will show you your active sessions:
buefer21@ada:~$ screen -ls There are screens on: 25255.pts-12.ada (04/17/2013 05:04:59 PM) (Detached) 25245.pts-12.ada (04/17/2013 05:04:56 PM) (Detached) 24697.pts-12.ada (04/17/2013 04:13:32 PM) (Detached)
Type your reattach command, followed by something that uniquely identifies that session:
buefer21@ada:~$ screen -dr 25255 --------- OR ---------- buefer21@ada:~$ screen -dr 24
Here the third session is the only one with '24' in it, so I can use that to identify it. You can also name your sessions; when you start a new screen, use the -S flag:
buefer21@ada:~$ screen -S schoolwork
That'll start a screen session name 'schoolwork', so you can just reattach with
screen -dr schoolwork.
Make sure to try
C-a ? to see the manual of available commands.
Session management / Attaching
To be done on the command line outside of a screen
||start a new screen session with name <name>|
||list running sessions/screens|
||attach to a running session|
|<code.screen -r <name></code>|| reattach to session <name> (can also be a uniquely identifying string from |
||The 'ultimate reattach'. Attaches to a screen session. If the session is attached elsewhere, detaches that other display. If no session exists, creates one. If multiple sessions exist, uses the first one.|
Every command hereafter are screen key commands which use the meta-escape key (
Ctrl + a by default, written as
They are used within screen to modify the current session.
||detach and logout (quick exit)|
||create new window|
||rename current window|
||change to last-visited active window|
||change to window by number (only for windows 0 to 9)|
||change to window by number or name|
||change to next window in list|
||change to previous window in list|
||see window list (allows you to select a window to change to)|
||show window bar (if you don't have window bar)|
| Close all applications in the current window (including shell, using
||close current window|
||kill current window (not recommended)|
||kill all windows (not recommended)|
||split display horizontally|
|or C-a V||split display vertically|
||jump to next display region|
||remove current region|
||remove all regions but the current one|