vote up 15 vote down star
12

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.

flag
This belongs on superuser. – Captain Segfault Nov 5 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 at 1:31
3  
screen is so useful it belongs on all the sites: stackoverflow.com/questions/70614/… – Zac Thompson Nov 5 at 9:14

9 Answers

vote up 17 vote down check

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

screen /dev/ttyS0 19200
link|flag
this is one of my favorite things to freak people out with, truly one of screen's least expected features – epic9x Nov 9 at 14:00
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. – packs Nov 9 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 at 11:00
This literally made my day. Thanks for sharing! – faultyserver Dec 3 at 23:59
vote up 6 vote down

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|flag
@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 at 0:33
vote up 3 vote down

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|flag
Considering that ctrl+a is used too often outside of screen (beginning of line in bash anyone?) I like this. – packs Nov 5 at 12:42
vote up 3 vote down

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|flag
vote up 3 vote down

From KTamas's amswer: More than one people 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|flag
vote up 2 vote down

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|flag
vote up 1 vote down

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|flag
vote up 1 vote down

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|flag
vote up 1 vote down

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|flag
3  
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 at 6:16
Why didn't I know that? Thanks! – Josh Nov 11 at 13:49

Your Answer

Get an OpenID
or
never shown

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