Screen power tips: .screenrc

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

15 Comments »

  1. Harith Said,

    July 11, 2007 @ 9:21 am

    Matt

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

    May be next time :-)

  2. Dallas Said,

    July 11, 2007 @ 10:05 am

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

  3. Romain Said,

    July 11, 2007 @ 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.

  4. Kirill Said,

    July 11, 2007 @ 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%=”

  5. egorych Said,

    July 11, 2007 @ 11:48 am

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

  6. James Byers Said,

    July 11, 2007 @ 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…

  7. joshua schachter Said,

    July 11, 2007 @ 10:25 pm

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

    escape ^Tt

  8. Peter Ortner Said,

    July 11, 2007 @ 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.

  9. Wit Said,

    July 14, 2007 @ 7:24 am

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

  10. DJtoo Said,

    July 14, 2007 @ 11:41 pm

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

  11. Alok Said,

    July 15, 2007 @ 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?

  12. crimanysakes Said,

    July 25, 2007 @ 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.

  13. Arne Vogel Said,

    July 31, 2007 @ 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?

  14. Matthew McEachen Said,

    September 19, 2007 @ 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.

  15. proson Said,

    September 22, 2007 @ 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.

RSS feed for comments on this post

Got a webmaster-related question or suggestion that is not directly related to the topic of this entry? Instead of posting it here, your best bet is our official Google forum linked from http://www.google.com/webmasters/

Also, I pre-moderate first-time commenters. Please review my comment policy before leaving a comment.