Computer And Technologies

Computer And Technologies: Screen Tips (Linux)

Thursday 7 May 2009

Screen Tips (Linux)

Screen is a terminal emulator that allows you to detach/reattach to running programs. This allows you to have many programs running in tabs on one console connection. You can then detach from that instance of screen, logout, go home, login and reattach as if nothing happened.

This makes it significantly easier to have the same working environment over the VPN as you do at your desktop.
Quick Introduction

type: screen

You will be sitting at a bash shell as if nothing changed. However, you are now running bash inside of screen. All commands that are directed at screen are prefixed with Ctrl-a (C-a)

Now, try this: C-a c as in Ctrl-a create new tab.

And then: C-a " as in Ctrl-a (quote)

This should list the two tabs you have open, you can use up and down to move between them.

Launch vim and type some words in the vim session. Now hit: C-a p as in Ctrl-a previous.

Your vim will dissappear and you will be at your first tab again, at a bash prompt.

Now hit: C-a d (Ctrl-a detach) to drop you back to the original command line. Do a quick ps aux | grep screen to see your screen session is still running.

You can actually exit the shell session or completely disconnect from your ssh session (like ssh to blizzard) and your screen will still be there waiting for you.

When you are ready to reconnect to your screen just type: screen -r
Command Overview

Key
Action :- Ctrl-a c
New tab :- Ctrl-a n
Next tab :- Ctrl-a p
Prev tab :- Ctrl-a "

List tabs, interactively choose 1

Ctrl-a Ctrl-a

Goto last tab :- Ctrl-a N
Goto N tab :- Ctrl-a d

Detact from session :- screen -r

Reattach to a session (run from command line) :- screen -d -r

Reattach to a session, detaching an attached session first if necessary (nice if you want to see a running screen state from a different location)
screen -x

Attach to your running session (run from command line). This allows you to have two terminal windows connected to the same screen session (yes, you can watch yourself type)

Ctrl-a A


Rename this tab
Ctrl-a S

Split current tab into two horizontally into regions

Ctrl-a :resize
Resize current region
Ctrl-a tab

Move to next region
Ctrl-a M

Monitor a tab for activity
Ctrl-a _

Monitor a tab for silence
~/.screenrc

Add these lines to your ~/.screenrc for some prettiness:

startup_message off
hardstatus alwayslastline
hardstatus string '%{.k}%{g}[ %{G}%H %{g}][%= %{wk}%?%-Lw%?%{=b kR}(%{W}%n*%f %t%?(%u)%?%{=b kR})%{= kw}%?%+Lw%?%?%= %{g}][%{Y}%l%{g}]%{=b C}[ %m/%d %c ]%{W}'


This will stop displaying the welcome message and add a status line across the bottom that lists the host, your open tabs, the servers cpu usage and the current time

No comments:

Post a Comment