Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Since I use the *nix command screen all day, and I couldn't find anyone starting this question, I figured it should be started. You know the drill: community wiki, one answer per features so we all can vote.

share

locked by voretaq7 Nov 8 '12 at 17:32

This question exists because it has historical significance, but it is not considered a good, on-topic question for this site, so please do not use it as evidence that you can ask similar questions here. This question and its answers are frozen and cannot be changed. More info: help center.

5  
screen is so useful it belongs on all the sites: stackoverflow.com/questions/70614/gnu-screen-survival-guide –  Zac Thompson Nov 5 '09 at 9:14

11 Answers 11

up vote 31 down vote accepted

I love using it for connecting to serial consoles, i.e.

screen /dev/ttyS0 19200

This command simply opens up a connection to serial port 0 (ttyS0) with a baud speed of 19200

share
    
this is one of my favorite things to freak people out with, truly one of screen's least expected features –  epic9x Nov 9 '09 at 14:00
1  
And truly one of my favorites. No need to deal with, or configure, minicom, conserver, etc. I felt like a little kid in a candy store when I discovered this. –  Scott Pack Nov 9 '09 at 14:21
    
Absolutely - it's nice to have a screen session open, split into two windows, with both USB-Serial dongles visible. –  dotwaffle Nov 11 '09 at 11:00

Not exactly a "hidden feature"; but a properly setup .screenrc file can make a world of difference. One of the better examples out there can be found by googling screenrc and 'brad sims' - he has an excellent file to tinker with.

that said, my favourite setting would be bindkey:

# bind F7  to detach screen session from this terminal
# bind F8  to kill current screen window.
# bind F9  to create a new screen
# bind F10 to rename current screen window
# bind F11 to move to previous window
# bind F12 to move to next window
bindkey -k k7 detach
bindkey -k k8 kill
bindkey -k k9 screen
bindkey -k k; title
bindkey -k F1 prev
bindkey -k F2 next
share
2  
Considering that ctrl+a is used too often outside of screen (beginning of line in bash anyone?) I like this. –  Scott Pack Nov 5 '09 at 12:42
1  
ctrl+a/ctrl+e for moving the cursor, but also when minicom is running in a screen. Ctrl+a,a,o for options... –  petrus Sep 17 '10 at 17:52

A little cheat sheet I have printed out for myself;

(Note: Everything is preceeded by Ctrl-A)

A: rename a window   
": show a list of windows   
d: detatch session

And screen -D -R to deattach and reattach a running session (in case you somehow lose access to your session).

None of these are really hidden features, but these are the features I find to be the most useful.

share

It's a core feature, but of course the best is Ctrl-A: to talk directly to screen. : screen -t title ssh hostname etc.

share

I can't remember who I stole this from (someone on dotfile.org). I've modified it slightly for ssh:

#!/bin/sh
# scr - Runs a command in a fresh screen
#
# Get the current directory and the name of command

wd=`pwd`
cmd=$1
shift

# We can tell if we are running inside screen by looking
# for the STY environment variable.  If it is not set we
# only need to run the command, but if it is set then
# we need to use screen.

if [ -z "$STY" ]; then
        $cmd $*
else
        # Screen needs to change directory so that
        # relative file names are resolved correctly.
        screen -X chdir $wd

        # Ask screen to run the command
        if [ $cmd == "ssh" ]; then
                screen -X screen -t ""${1##*@}"" $cmd $*
        else
                screen -X screen -t "$cmd $*" $cmd $*
        fi
fi

Then I set the following bash aliases:

vim() {
        scr vim $*
}

man() {
        scr man $*
}

info() {
        scr info $*
}

watch() {
        scr watch $*
}

ssh() {
        scr ssh $*
}

It opens a new screen for the above aliases and iff using ssh, it renames the screen title with the ssh hostname.

Cheers z0mbix

share
    
:o. Did you lift and adapt it from me? gist.github.com/137214 –  VxJasonxV Jan 12 '11 at 0:52
    
No, I think it was from a last.fm staff member who blogger about it once. –  z0mbix Feb 2 '11 at 17:40

One nice feature: you can use backtick to pull in extra info for display in a caption. For example, I have a script that output a one-line summary of new mail counts in various folders, and I have that appear in the bottom line if my screen session along with the hostname with a config that looks like this:

backtick 1 15 15 /home/waltermundt/bin/newmail

caption always
caption string "%{.kW}%1` example.com %{.bW}%-w%{.rW}%n %t%{-}%+w %{.gW}%h%{-}"

The key is the %1` bit, which refers to the output of backtick job 1.

(I use hardstatus as the xterm title string and have it set differently, thus the use of caption instead of hardstatus alwayslastline.)

share

The best feature of screen is Byobu (formerly screen-profiles) which comes with Ubuntu by default since Jaunty: https://launchpad.net/byobu

It's a configuration manager with very nice defaults, tons of status notifications and useful keyboard shortcuts (i.e. f2 for new screen, f3-f4 for prev/next etc.)

I really don't go anywhere without it anymore :)

share

From KTamas's amswer: More than one person can use the same screen, i.e. if a friend of yours ssh into your computer, then he can connect to your screen. It's great when two or three people are working on the same projects.

share
1  
This is much better for following what remote support users are doing, and killing their session if they're upto no good! –  Tom O'Connor Oct 15 '11 at 18:40

One thing I find useful is that screen can emulate a larger width than your terminal. I find this useful if I'm using less to real log files, and I don't want the lines to wrap. Using:

Ctrl-A:width -w 999

I can set screen's with to be wider than my terminal, and log lines in less won't wrap.

share
10  
FYI, the less option -s will tell it not to wrap lines. You can use Left and Right to scroll the lines. –  MikeyB Nov 11 '09 at 6:16

Not a "hidden" feature, but the ability to share a screen session with another active user is very useful.

There are complicated ways to set up screen sharing, including access control permissions and user name management. What I most often do with coworkers is much more quick & dirty:

  1. Log into machine in question in new window.
  2. Allow anyone to write to my terminal: chmod 777 $(tty)
  3. Sudo to their account: sudo su <username>
  4. Share their screen: screen -x <session>

This doesn't require any advance configuration or password sharing.

share

The ability to change the control key with -ethat when starting screen. I use it so I can nest screen sessions inside each other. Example: "screen -e ^w^x" makes the control key ctr-w.

share

Not the answer you're looking for? Browse other questions tagged or ask your own question.