31
votes

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.

1

11 Answers 11

31
votes

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

3
  • this is one of my favorite things to freak people out with, truly one of screen's least expected features
    – epic9x
    Nov 9, 2009 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, 2009 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, 2009 at 11:00
10
votes

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

0
10
votes

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.

1
  • 1
    This is much better for following what remote support users are doing, and killing their session if they're upto no good! Oct 15, 2011 at 18:40
6
votes

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
2
  • 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, 2009 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, 2010 at 17:52
6
votes

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

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

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.

1
  • 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, 2009 at 6:16
4
votes

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.

2
votes

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

2
votes

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.

1
vote

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.

1
vote

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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .