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

19 Responses to Screen power tips: .screenrc (Leave a comment)

  1. Harith

    Matt

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

    May be next time :-)

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

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

    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. The last advice (the answer in FAQ) was very useful. I thought I couldn’t solve this problem.

  6. 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. I use control-t; nothing much seems to use it.

    escape ^Tt

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

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

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

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

  12. crimanysakes

    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

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

  16. Adam

    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.

  17. enki

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

  18. bala

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

  19. Julio Leiva

    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

Your email address will not be published. Required fields are marked *

*

If you have a question about your site specifically or a general question about search, your best bet is to post in our Webmaster Help Forum linked from http://google.com/webmasters

If you comment, please use your personal name, not your business name. Business names can sound salesy or spammy, and I would like to try people leaving their actual name instead.

You may 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>

css.php