Using Linux screen to be productive

Screen is a full-screen window manager that multiplexes a physical terminal between several processes thus creating a number of virtual terminals. Creating virtual terminals is like having a number of monitors attached to the server and you are connecting and resuming each session every time you connect to them. This is an invaluable tool for system administrators and a more preferred way to resume a session rather than using VNC (especially if you are only using the command line interface).

I will be explaining how to use screen without too much theory and talk.

Starting a new screen session or reattach to existing session:
$ screen -R

List all the screen sessions:
$ screen -ls

Creating a new virtual terminal (from inside the screen session):
Ctrl-a, c

Detaching from the virtual terminal back to the CLI:
Ctrl-a, d

Hop to the next/previous virtual terminal:
Ctrl-a, n and Ctrl-a, p

Hop to a virtual terminal number:
Ctrl-a, 0-9

Kill all virtual terminals:
Ctrl-a, \

Password protect a screen session (lock):
Ctrl-a, x

Help on interactive screen commands:
Ctrl-a, ?

Example of usage of putting a couple of screens on a server, one for top, another for vmstat and another one for iostat:

Main Terminal:
james@earth:~$ screen -R

Virtual Terminal 0:
james@earth:~$ top
[ Press Ctrl-a, c to create a new virtual terminal ]

Virtual Terminal 1:
james@earth:~$ vmstat 5
[ Press Ctrl-a, c to create a new virtual terminal ]

Virtual Terminal 2:
james@earth:~$ iostat 5
[ Press Ctrl-a, c to create a new virtual terminal ]

Hop to the virtual terminal showing top:
[ Press Ctrl-a, 0 to go to terminal 0 ]

Detach from screen and return to main terminal window:
[ Press Ctrl-a, d ]

Display list of screen sessions:
james@earth:~$ screen -ls
There is a screen on: (04/22/2012 09:41:33 AM) (Detached)
1 Socket in /var/run/screen/S-james.

No comments: