GNU Screen

From DuncanWiki
Jump to: navigation, search

GNU Screen is one of the most useful pieces of software I've ever come across. It allows you to keep a terminal up and running that you're able to re-connect to remotely, share a terminal with another user, split your terminal into sections & much more.

Apparently there's discussion as to what exactly screen is. Is it a terminal multiplexer? Is it a window manager? I guess it really depends on where you're standing. People who are using GNOME, KDE, Mac OS X, Windows or any other environment where you run a Terminal Emulator then it's more of a multiplexer. If you're just running a machine without a window manager, then I guess screen IS your window manager.

But whatever.

Contents

Configuration

Configuring screen can be an incredibly tedious process involving hours and hours of reading documentation, or you can just search the web for someone else's .screenrc... like mine.

My .screenrc

My .screenrc can be downloaded at http://files.duncanbrown.org/linux/dotfiles/.screenrc

Here is a screen capture of what my current screen session looks like :

Screen Screenshot.png

The weather information and current Load Average are collected by something other than screen, you can find that information on how it works at http://files.duncanbrown.org/linux/dotfiles

Set The Status Line To Something Useful

Add this to your .bashrc or .bash_profile

case $TERM in
 *screen*) export PROMPT_COMMAND='echo -ne "\033]0;${USER}@${HOSTNAME%%.*}:${PWD/#$HOME/~}\007"'   
   ;;
esac

Multi-User Mode

This is ripped directly from Gentoo's site, I need to clean it up so it's not a direct plagiary.

http://gentoo-wiki.com/HOWTO_Snoop_terminal_session#Screen

Using Screen in multiuser mode requires screen to be as setuid root. If you know about the potential security implications you can enable it by issuing

# chmod u+s `which screen`

We need to configure screen to use multiuser mode and change privileges for the guest. Put the following commands into ~/.screenrc. You can also use them in a screen session after pressing ^A

multiuser on
aclchg snoopy -x "?"    #Revoke permission to execute any screen command
aclchg snoopy +x "wall" #Allow writing simple messages in the terminal status line
aclumask snoopy-wx      #Default permissions to windows
acladd snoopy           #Enable user snoopy to access screen session

Start screen:

user@localhost $ screen
user@localhost $ screen -ls
There is a screen on:
        11521.pts-4.hostname      (Multi, attached)
1 Socket in /var/run/screen/S-user.

Now the guest can attach to the screen:

snoopy@localhost $ screen -r user/11521

Using Screen

In this section you'll see letters prefaced with ^, this translates into CTRL-X.

Basic Commands

^A ? Help.
^A a Send the command character itself ("^a") to the program running in the current window.
^A t Show time, date, hostname, and some other stuff.
^A @ Do nothing. (Useful when you hit "^a" by mistake.)
^A : Enter command line mode. (For example, "^a :number 7" changes the window number of the current window to 7. See the man page for more details.)
^A ^Z Suspend screen. (You will be back at the shell you started screen from.)
^A d Detach screen. (Do this before you log out -- you will be back at the shell you started screen from.)

Window Navigation & Management

^A ^A Switch to the last used window
^A ^N Switch to the next window
^A ^P Switch to the previous window
^A 0 Switch to window number 0 (works with 0-9).
^A " Present a list of all windows for selection. Use the arrow or number keys (or vi- or Emacs-style cursor keys) to highlight a window and press <Enter> to switch to it.
^A c Create a new window with a shell and switch to that window
^A A Change the current window's title
^A ' Prompt for a window name/number to switch to
^A F Resize the window to the current region size
^A K Kill the current window
^A l Refresh current window
^A i Show information on the current window
^A N Show name & number of current window
'

Copy/Scrollback Mode

^A [ Enter scrollback mode
^A ] Send the contents of the paste buffer to the program running in the current window
h,j,k,l Move cursor left, down, up, right (as in vi/vim). Regular arrow keys also work.
^B Page up (<PageUp> key also works).
^F Page down (<PageDown> key also works).
<Space> Set mark. When the second mark is set, the text between the two marks will be put into screen's paste buffer and copy/scrollback mode will be exited.
^ Move to first nonwhitespace character on current line.
$ Move to last nonwhitespace character on current line.
0 Move to leftmost column.
c Set the left margin for block-mode copying.
C Set the right margin for block-mode copying.
x Exchange the first mark with the current cursor position. This is good for moving an already set mark.
<Esc> Exit copy/scrollback mode. (Any key that doesn't have another meaning will do this.)


A split screen featuring Mac OS X on top & GNU/Linux on the bottom

Regions allow looking at two or more screen windows at the same time.

Regions

^A S Split the current region horizontally.
Split the current region vertically.
^A ^I Switch focus to the next region.
^A Q Delete all regions but the current one. (This does not destroy any windows.)

I need to integrate the info from http://www.mail-archive.com/screen-users@gnu.org/msg01032.html

Logging

^A h Write a hardcopy of current window to hardcopy.N
^A H Toggles logging of current window to screenlog.N
'
'
'
'

Misc

^A
'
'
'
'

More Stuff

I've found that GNU Screen can be even more useful when you rotate your X11 display by 90 degrees! A split screen gives you much more usable real estate than a standard horizontal monitor. If you're interested, check out Rotating X.org Screens.

Personal tools