
GNU Screen - A Hacker's Ideal Terminal - soundphed
http://www.ibm.com/developerworks/aix/library/au-gnu_screen/
======
silentbicycle
You might want to consider tmux (<http://tmux.sourceforge.net/>) as an
alternative. Its cleaner (and, incidentally, BSD-licensed) codebase means that
it's getting features that have been gathering dust on screen's to-do list for
ages. Most notably, its dwm/XMonad-style layouts
(<http://tmux.sourceforge.net/tmux6.png>) are _really_ nice. AFAICT, screen
doesn't even officially have vertically split windows yet, it's still an
unofficial patch.

Either way, if you use Unix, learn to use screen or tmux. They're
_tremendously_ useful. (Also: Noisy wireless connections are the new flaky
dialup, when it comes to resuming shell sessions.)

~~~
soundphed
Thanks, I will look at that, looks rad! I just thought the article covered
some really key points about multiplexing terminals in general...

~~~
blasdel
tmux is not _rad_ , just clean -- see <http://caca.zoy.org/wiki/neercs> for a
truly _radical_ screen replacement:

    
    
      Grab a process that you forgot to start inside neercs
      Great screensaver
      Real time thumbnails of your shells
      Special effects when closing a window
      Various window layouts...

~~~
mahmud
How does any of this work when through putty or when connecting to X-less
unices from the myriad of non-Unix boxes out there?

~~~
cma
At least click the link. It is all done in ascii art.

------
mdakin
It also gives OSX RS-232 terminal emulation capability. As far as I know OSX
ships with no other such program. Once you get your USB dongle's driver
situation under control you just:

screen _device_ _baud_

ex:

screen /dev/tty.usbserial-FTDPZOEJ 115200

Very useful for embedded system hackers and others who still need to speak
RS-232.

~~~
blasdel
I have not used a single other serial console since I accidentally discovered
this feature in screen a few years ago. Hyperterminal, minicom, gtkterm, et.
al. were the bane of my existence.

------
mcantor
I often use idiosyncratic screen setups with very specifically-purposed
windows. I support this behavior with a special config file that launches
screen with certain windows pre-loaded for certain uses:

    
    
      source /home/mcantor/.screenrc
      chdir $SANDBOX/src
      screen 0:svn
      screen 1:lib
      screen 2:nosetests
      stuff "activate_environment\015"
      screen 3:ipython
      stuff "activate_environment\015ipython\015"
      screen 4:
      select 0
    

I use stuff because it's the most straightforward way to send commands with
carriage returns (015 in octal) to a window.

I make this even more effortless by using a special alias in my .bashrc:

    
    
      alias scd='screen -c /home/mcantor/.screenrc-dev'
    

I also use a few other aliases to support common uses:

    
    
      alias scr='screen -rd'
      alias scx='screen -x'
      alias lsc='screen -list'
    

Also, don't forget the very useful -S switch:

    
    
      screen -S someproject
    

Or, you can use Ctrl-a :sessionname, if you're already within a session, to
rename it. That way, screen -list and screen -r can use your sessionnames, and
you don't have to parse or remember the process ID's.

~~~
pyre
I really wish there was a way to use the sessionname in the hard status line
formatting.

~~~
mcantor
You're probably never going to read back this far in time, but, it's coming in
the next version.

------
dryicerx
I don't think I can live without it anymore.

There is no reason why you shouldn't use screen when ssh'ing in and working on
remote machines, it will save you tons of time in case the connection goes
down, plus allows your to keep a persistent working environment on remote
boxes.

    
    
        ssh -t user@host screen -rx
    

That will drop you immediately to a running screen on connect

~~~
mooism2
My remote `.bash_profile` ends

    
    
        screen -d -R
        logout
    

On the rare occasions that I don't want to run under screen, I run `ssh -t
user@host bash`.

~~~
pyre
I hope you mean on the server. IIRC, some things like GNOME will source
.profile or .bash_profile so that you can have globally customized $PATH,etc
variables.

~~~
mooism2
On remote servers, yes.

------
jazzychad
I use screen every day for administering multiple remote servers. I don't know
how I functioned before I used screen. One of the coolest things are
"backtick" commands you can put in the caption string. Here is a pastie of my
screenrc and one of the backtick files which displays the free RAM of the
system in the caption line, updating every 30 seconds (ymmv on the free RAM
command depending on how your distro's `free` command displays its output)

<http://pastie.org/633808>

------
barrkel
The difficulty of scrolling back in the buffer (C-a ESC PgUp is a longer and
more tedious key sequence than Shift+PgUp), and lack of full terminal support
(e.g. man, less, etc. don't restore screen contents on exit) mean I strictly
only use screen on ssh connections.

Perhaps the terminal support issue could be worked out with better termcap
etc. settings, but I haven't found the answers. I asked questions here:

[http://superuser.com/questions/23144/how-to-make-screen-
term...](http://superuser.com/questions/23144/how-to-make-screen-terminal-
emulation-act-more-like-xterm-or-rxvt-for-init-uninit)

... but no luck.

~~~
decklin
try "altscreen on". (see also the -a option, and
[http://www.gnu.org/software/screen/manual/html_node/Window-T...](http://www.gnu.org/software/screen/manual/html_node/Window-
Termcap.html)).

~~~
barrkel
The -a option didn't work, but altscreen on in my ~/.screenrc seems to have
worked. Thanks!

------
noonespecial
Many thanks for posting this. This is exactly the kind of thing I come to HN
to find. I use screen on occasion but never really had it in my mind that I
should be using it as a productivity tool.

I have once again found minor enlightenment and am already more productive
because of it. Its nice when procrastinating on HN turns into a net win!

------
chwahoo
Screen is great. I wish there were an analogous tool that let me group several
running X apps into a long-running session that I could connect to/disconnect
from locations. Any idea if this is possible today?

~~~
fhars
NX is supposedly able to do this, but last time I looked (which, admittedly,
was two or three years ago) you had to expect serious problems if the set of
available fonts on the different display servers was different (i.e. in all
realistic scenarios). Oh, and it only worked on x86-32.

~~~
abhijithoskeri
<http://partiwm.org/wiki/xpra>

------
tlrobinson
I've been satisfied with just using multiple tabs in Terminal.app in OS X, but
I'm curious if anyone has switched from that solution to screen and wouldn't
go back? (for local use in particular)

~~~
potatolicious
I use screen constantly and would never go back. The detachability is
_incredibly_ useful. Say I had to go to a meeting - I shut my laptop and it
goes to sleep. This would normally kill any SSH session (and thus leave vim
swap files lying about in my case)... but with screen I can just pick up where
I left off last time.

It's also great if you want to run something big - say a job that would take 5
hours. I'm free to do whatever I want without fear that killing my ssh session
will also kill the job.

~~~
scott_s
Your second scenario can be handled with nohup from within a vanilla ssh
session.

~~~
graywh
There's also disown, for that matter, but how can you re-connect to the
process?

------
hugothefrog
I've been using Screen for a number of years now, but I've recently come
across Ubuntu's repackaging of it -
[https://help.ubuntu.com/9.04/serverguide/C/screen-
profiles.h...](https://help.ubuntu.com/9.04/serverguide/C/screen-
profiles.html). This seems like a fantastic way to introduce screen to new
users, who are probably intimidated by screen's default bare-bones config.

------
elbenshira
Screen uses C-a as its "command" character. Unfortunately, C-a means "go to
start of line" in emacs and terminals. The solution?

In your .screenrc file:

    
    
        escape ^Ww
    

This will default C-w as the command character.

~~~
cschep
Isn't C-w kill-region in emacs? I recently came up against this problem too,
but what else to change it to .. ?

~~~
silentbicycle
I like ` (just backtick, no control), though that clashes with Lisp a bit. (I
don't usually use Lisp inside tmux, though.)

~~~
surki
` cannot be used since in terminal C + ` or C + SPC or C + @ translates into
same thing(only allowed characters are @ [ \ ] ^ and _ ). I personally prefer
using \

~~~
silentbicycle
Oh, I'm using just ` , not C-`. It's like hitting ESC in vi. (I also noticed
that space and shift-space are indistinguishable, which is a bit annoying
because in Emacs I use S-spc for languages with lots_of_soft_spacing or-
several-words-joined-with-dashes.)

~~~
cturner
Readers - I found the .screenrc change for this not-entirely-obvious. You need
to say escape ``

whereas you'd have thought it would be just escape `

~~~
silentbicycle
The second character doesn't have to be another ` - that option controls what
you type for an unescaped version of your meta key. I use

    
    
      escape `~
    

and reserve `` for switching to the most recently used window. (It looks like
I didn't need to specify that explicitly.)

------
JeremyChase
Screen is an amazingly useful tool. If you aren't using it or something like
it, you are really making life more difficult for yourself.

If you want something that isn't GNU or GPL'd, take a look at `tmux`.

~~~
e1ven
I'm just curious- Why would you want to specifically avoid the GPL?

~~~
pyre
The same way there are people that want their entire software usage to be
GPL/MIT/BSD/etc, there are people that want everything to be non-GPL. Unless
you are going to be hacking on GNU Screen and feel the need to do something
that the GPL forbids, there's really no reason to stop yourself from _using_ a
software package just because it's GPL-licensed.

~~~
tedunangst
I think it's ironic that your argument is remarkably similar to "nothing stops
you from using a closed source program unless you planned to start hacking on
the source." Sometimes you don't know when you start using something what
amount of hacking may be required.

~~~
pyre
Yes, but you _can_ contribute to GPL-licensed projects. It's just specific
things that you are limited in. We're talking orders of magnitude. 'closed-
source and GPL' and 'MIT/BSD and GPL' aren't even in the same ballpark.

~~~
apotheon
One thing you can't do with a GPLed application -- and something I do all the
time -- is try to support copyfree licensing rather than copyleft licensing.

------
Keyframe
I use screen for bazillion of years already. When doing stuff with django I
like to C-a c to make a new screen, then C-a :resize 10 so that I have two
screens on one (you can switch between them with C-a TAB). So in the smaller
one I run server and in larger whatever I need to. Excellent when having two
or more monitors with one being dedicated to full screen terminal setup like
that.

------
TallGuyShort
This IS a hacker's ideal Terminal - a while ago I set out to write my own
shell with all the features I wanted. A huge portion of the functionality I
intended to implement is accomplished with GNU Screen. Since I found Screen -
I haven't felt enough need to keep developing my own shell!

------
soundphed
I found this link on how to patch/compile Screen 4.0.3 on Snow Leopard...the
one out of the box is kind of buggy, and does not support 256 colors...

<http://trac.macports.org/ticket/20862>

------
garply
In the same vein, if you use a repl on a remote machine you should check out
detachtty if you're not already using it. It's particularly nice for use
within emacs because it doesn't eat the whole screen and it doesn't eat ^A.

~~~
jazzychad
fwiw, screen doesn't "eat ^A"

You can send ^a to a window in screen by typing "^a a" - I do this everyday
using emacs inside of screen. It becomes second nature.

~~~
coryrc
I changed to C-\

------
Luyt
'dtach' is a nice utility too, a kind of lightweight-screen. It's in the BSD
ports.

------
wglb
Highly valuable.

See [http://renesd.blogspot.com/2009/09/screen-for-ghetto-
servers...](http://renesd.blogspot.com/2009/09/screen-for-ghetto-servers-and-
startup.html) for more pointers.

------
btw0
I recently found BSD implementation -- tmux better than GNU screen.

~~~
tome
Better in what way?

~~~
silentbicycle
For starters, it has built-in dwm/XMonad-style layouts, while screen has taken
ages to even get vertically split windows.

~~~
pyre
In general, one should probably know their way around GNU screen in addition
to tmux just because you'll probably encounter it on more installations. Much
in the same way that it's really to your benefit to know a bit about vi even
if you are an Emacs user.

~~~
silentbicycle
Agreed. They're both _incredibly_ handy, and even if you only learn the common
feature subset, it's still a huge win.

------
tome
All my rxvts run screen automatically. This means if I then leave my
workstation and need to access one of the terminals remotely I can just
duplicate it with screen -x.

[Edited for clarity]

------
surki
I posted my config sometime back. <http://news.ycombinator.com/item?id=843630>

------
bdotdub
anyone care to share their screenrc? heres mine:
<http://github.com/bdotdub/dotfiles/blob/master/screenrc>

~~~
silentbicycle
The most notable part of mine is

    
    
       # Set up my status line at the bottom of every frame
       caption always "%{gb}  %{ck}%m-%d %C %{gb}  %{gb}%?%-Lw%?%{ck}%n*%f %t%?(%u)%?%{gb}%?%+Lw%?"
    

I use tmux now, though. (it has a statusbar similar to the above by default)

------
apotheon
I prefer tmux.

~~~
lanaer
I installed tmux, but have not yet played with it. I know I want to, simply
because it supports vertical splits…

