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.

link|improve this question
This belongs on superuser. – Captain Segfault Nov 5 '09 at 1:14
1  
@Captain Segfault -- I wasn't really sure where to put it. I figured sysadmins might know more about screen, but maybe I made the wrong choice. – Josh Nov 5 '09 at 1:31
4  
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
feedback

11 Answers

up vote 26 down vote accepted

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

screen /dev/ttyS0 19200
link|improve this answer
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
This literally made my day. Thanks for sharing! – faultyserver Dec 3 '09 at 23:59
6  
What does this command do ? – Lamnk Aug 7 '10 at 19:19
feedback

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 :)

link|improve this answer
@KTamas: I moved your feature of two people being able to share the same screen to a new answer so I could vote it up. Please edit it and post how that's done!! – Josh Nov 11 '09 at 0:33
feedback

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.

link|improve this answer
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
feedback

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
link|improve this answer
1  
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
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
feedback

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

link|improve this answer
: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
feedback

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.

link|improve this answer
7  
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
Why didn't I know that? Thanks! – Josh Nov 11 '09 at 13:49
feedback

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.

link|improve this answer
feedback

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.)

link|improve this answer
feedback

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.

link|improve this answer
feedback

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

link|improve this answer
feedback

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.

link|improve this answer
feedback

Your Answer

 
or
required, but never shown

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