Screen power tips: .screenrc

July 11, 2007

in How to

If you’ve read my brief tutorial on screen and want to know more, here are some power user tips:

screen -ls will list the current screen sessions running on a machine.
Control-a Control-a will toggle between your current shell and your previous shell.
Control-a d will detach a session.
Control-a ” will show all the current shells. Use the up/down cursor keys and then press enter to select a shell.

Those commands will help you navigate the windows within a session.

In most Linux terminals, Control-a takes you to the beginning of your line. Suppose you want to keep that behavior? Luckily it’s easy to bind screen’s “escape” key to something other than Control-a. You can modify screen’s settings by creating a ~/.screenrc file in your home directory. Here’s what my .screenrc file looks like:

escape ^Bb # Instead of Control-a, make the escape/command character be Control-b

autodetach on # Autodetach session on hangup instead of terminating screen completely

startup_message off # Turn off the splash screen

defscrollback 30000 # Use a 30000-line scrollback buffer

termcapinfo xterm ti@:te@
# From http://www4.informatik.uni-erlangen.de/~jnweiger/screen-faq.html
# Q: My xterm scrollbar does not work with screen.
# A: The problem is that xterm will not allow scrolling if the alternate text buffer is selected. The standard definitions of the termcap initialize capabilities ti and te switch to and from the alternate text buffer. (The scrollbar also does not work when you start e.g. ‘vi’). You can tell screen not to use these initialisations by adding the line “termcapinfo xterm ti@:te@” to your ~/.screenrc file.

Most of these settings are pretty self-explanatory. Anyway, that’s how I set-up my screen. :)

{ 19 comments… read them below or add one }

Harith July 11, 2007 at 9:21 am

Matt

But you promised some Gadgets too, and may be an Emmy-Oz update!

May be next time :-)

Dallas July 11, 2007 at 10:05 am

“screen -list” will also show current sessions ^_^

Romain July 11, 2007 at 11:18 am

Control-b isn’t a very good choice in general because it’s a very useful key in the shell once you’ve learned to use Control-b/Control-f instead of the left and right arrows (resp.) to move the cursor.

Also, Control-b is a very common key in Emacs (C-x b, C-x C-b, etc).

I usually recommend Control-z.

Kirill July 11, 2007 at 11:31 am

Personally, I also prefer:

caption always “%{kB}%?%-Lw%?%{bw}%n*%f %t%?(%u)%?%{kB}%?%+Lw%?”
hardstatus alwayslastline “%{BW}%16=%l %{BW}%50=%d/%m/%Y %{BW}%80=%c%=”

egorych July 11, 2007 at 11:48 am

The last advice (the answer in FAQ) was very useful. I thought I couldn’t solve this problem.

James Byers July 11, 2007 at 1:08 pm

Here’s one mainly for emacs users. Save (C-x-s) suddenly stop working? You accidentally turned flow control on in screen (C-a-f), trapping C-s. Turn flow control back off with another C-a-f and all’s well. This almost drove me to throw my laptop out the window before I figured it out…

joshua schachter July 11, 2007 at 10:25 pm

I use control-t; nothing much seems to use it.

escape ^Tt

Peter Ortner July 11, 2007 at 10:51 pm

You can use Ctrl+A, A (or C-A-A to the Emacs users) to send Ctrl+A to the program in the current screen window, by default. This isn’t too arduous.

I also turn off the visual bell (i.e. the screen flash that’s substituted for the bell) with the following .screenrc line:

vbell off # turn off visual bell

screen instead rings the audible bell on my terminal.

Anyway, thanks for the info Matt.

Wit July 14, 2007 at 7:24 am

Only 6 comments Matt (!?) Apparently this post was way too geeky :) Are you aiming for “the long tail” – perchance?

DJtoo July 14, 2007 at 11:41 pm

“screen -list” will also show current sessions ^_^

Alok July 15, 2007 at 8:13 pm

The Konsole or any other Linux terminal will give you multiple panes for different sessions, so I wonder why is screen desirable?

crimanysakes July 25, 2007 at 9:44 pm

Probably the best reason for using screen is If you are working at, well, work, and want to go home and work, and you are using terminals and ssh, it’s really easy to just pick up where you left off.

Can’t really do that with konsole, unless you are vnc’ing; which unless you are doing graphical development would be a major bandwidth hog.

Arne Vogel July 31, 2007 at 12:00 pm

“The Konsole or any other Linux terminal will give you multiple panes for different sessions, so I wonder why is screen desirable?”

And this is no use when ssh’ing into a server, unless you want to open one session for every window where you otherwise could just [CTRL-A n] to open a new shell almost instantly.

Neither does Konsole offer any protection against loss of connection. When my ssh dies while I’m using screen on the server (for example if the client machine enters standby and the connection times out), all that happens is that the screen session is detached. I open another ssh, switch to super-user (I don’t allow sshd to open root shells) and type “screen -rr” and all my VIMs and manpages are right there again.

@Keniki: Do you have any signal to contribute or just noise?

Matthew McEachen September 19, 2007 at 9:34 pm

Multiplexed screen is the bees’ knees!

N clients can connect to the same instance of screen by using the “-x” option. One glitch is that the users *login* needs to be to the shared account, due to /dev/tty permission issues. Simply sudo’ing to the shared account won’t work. A simple solution is to have the users copy their ssh public key into the shared account’s ~/.ssh/authorized_keys, then everyone can ssh sharedaccount@remotehost.

So, once you’ve got that all set up, N people can be typing simultaneously (preferably one at a time) into the same shell. It’s great for pair programming, mentoring, or dangerous system administration stuff where another set of eyes can help reduce the chance of catastrophe.

proson September 22, 2007 at 6:18 am

thanks for your tips. I don’t Unix much these days. since I am not a developer but it’s great to hear tips and tricks or Unix or linux machine.

Adam December 21, 2008 at 9:29 pm

Thanks for your tips.

How can to ctrl-a ctrl-a with Ctrl-b as an escape key? The answer seems not ctrl-b ctrl-a.

enki March 29, 2009 at 5:10 pm

One other solution is to use M-a (alt-a) in emacs, since it essentially does the same thing.

bala June 18, 2009 at 2:31 am

can you how to bind ctrl+tab and ctrl+shift+tab keystrokes to move to other screens??

Julio Leiva June 29, 2009 at 8:55 am

Hi guys

I’m using screen for many tasks on my system
It is working ok in all my systems,but suddenly in one box screen begins acting up.
I’m able to create the screen and go back and forth from it.
The problem comes when I want to terminate the screen using the ‘exit’ command inside of the screen, it hangs for ever.If I use CRTL+A,K no problem.
That way of closing the screen works all over the place except there.I’ve checked for differences but I can’t see any….
Any help is really appreciate.
Thanks

Leave a Comment

You can use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Previous post: A quick tutorial on screen

Next post: An unusual email from Amazon