<p>I've just introduced a friend to <strong>GNU Screen</strong> and they're having a hard time getting used to it. That makes me think about the essential things he needs to know about the excellent <strong>Screen</strong> utility, the same things that you'd think worthwhile to teach someone, a beginner, from the ground up. What are some analogies and handy tips for remembering binds, etc.?</p>

<p>It would be awesome.</p>

[{'answer_id': 70683, 'author': 'agnul', 'author_id': 6069, 'author_profile': 'https://Stackoverflow.com/users/6069', 'pm_score': 5, 'selected': False, 'text': '<p>If your friend is in the habit of pressing <code>^A</code> to get to the beginning of the line in Bash, he/she is in for some surprises, since <code>^A</code> is the screen command key binding. Usually I end up with a frozen screen, possibly because of some random key I pressed after <code>^A</code> :-) </p>\n\n<p>In those cases I try</p>\n\n<p><code>^A s</code> and <code>^A q</code> block/unblock terminal scrolling</p>\n\n<p>to fix that. To go to the beginning of a line inside screen, the key sequence is <code>^A a</code>.</p>\n'}, {'answer_id': 70716, 'author': 'tadeusz', 'author_id': 7593, 'author_profile': 'https://Stackoverflow.com/users/7593', 'pm_score': 3, 'selected': False, 'text': '<p><kbd>Ctrl</kbd>+<kbd>a</kbd> is a special key.</p>\n\n<p><kbd>Ctrl</kbd>+<kbd>a</kbd> <kbd>d</kbd> - [d]etach, leave programs (irssi?) in background, go home.</p>\n\n<p><kbd>Ctrl</kbd>+<kbd>a</kbd> <kbd>c</kbd> [c]reate a new window\n<kbd>Ctrl</kbd>+<kbd>a</kbd> <kbd>0-9</kbd> switch between windows by number</p>\n\n<p>screen -r - get back to detached session</p>\n\n<p>That covers 90% of use cases. Do not try to show all the functionality at the single time.</p>\n'}, {'answer_id': 70735, 'author': 'Niko Gunadi', 'author_id': 4499, 'author_profile': 'https://Stackoverflow.com/users/4499', 'pm_score': 3, 'selected': False, 'text': '<p><kbd>Ctrl</kbd>+<kbd>A</kbd> is the base command</p>\n\n<p><kbd>Ctrl</kbd>+<kbd>A</kbd> <kbd>N</kbd> = go to the ***N***ext screen</p>\n\n<p><kbd>Ctrl</kbd>+<kbd>A</kbd> <kbd>P</kbd> = go to the ***P***revious screen</p>\n\n<p><kbd>Ctrl</kbd>+<kbd>A</kbd> <kbd>C</kbd> = ***C***reate new screen</p>\n\n<p><kbd>Ctrl</kbd>+<kbd>A</kbd> <kbd>D</kbd> = ***D***etach your screen</p>\n'}, {'answer_id': 70765, 'author': 'Greg Hewgill', 'author_id': 893, 'author_profile': 'https://Stackoverflow.com/users/893', 'pm_score': 8, 'selected': True, 'text': "<p>I've been using <code>Screen</code> for over 10 years and probably use less than half the features. So it's definitely not necessary to learn all its features right away (and I wouldn't recommend trying). My day-to-day commands are:</p>\n\n<pre><code>^A ^W - window list, where am I\n^A ^C - create new window\n^A space - next window\n^A p - previous window\n^A ^A - switch to previous screen (toggle)\n^A [0-9] - go to window [0-9]\n^A esc - copy mode, which I use for scrollback\n</code></pre>\n\n<p>I think that's it. I sometimes use the split screen features, but certainly not daily. The other tip is if screen seems to have locked up because you hit some random key combination by accident, do both <code>^Q</code> and <code>^A ^Q</code> to try to unlock it.</p>\n"}, {'answer_id': 70801, 'author': 'James Muscat', 'author_id': 11643, 'author_profile': 'https://Stackoverflow.com/users/11643', 'pm_score': 5, 'selected': False, 'text': '<p><kbd>Ctrl</kbd>+<kbd>A</kbd> ? - show the help screen!</p>\n'}, {'answer_id': 70882, 'author': 'Roel', 'author_id': 11449, 'author_profile': 'https://Stackoverflow.com/users/11449', 'pm_score': 5, 'selected': False, 'text': '<p>I couldn\'t get used to screen until I found a way to set a \'status bar\' at the bottom of the screen that shows what \'tab\' or \'virtual screen\' you\'re on and which other ones there are. Here is my setup:</p>\n\n<pre><code>[roel@roel ~]$ cat .screenrc\n# Here comes the pain...\ncaption always "%{=b dw}:%{-b dw}:%{=b dk}[ %{-b dw}%{-b dg}$USER%{-b dw}@%{-b dg}%H %{=b dk}] [ %= %?%{-b dg}%-Lw%?%{+b dk}(%{+b dw}%n:%t%{+b dk})%?(%u)%?%{-b dw}%?%{-b dg}%+Lw%? %{=b dk}]%{-b dw}:%{+b dw}:"\n\nbacktick 2 5 5 $HOME/scripts/meminfo\nhardstatus alwayslastline "%{+b dw}:%{-b dw}:%{+b dk}[%{-b dg} %0C:%s%a %{=b dk}]-[   %{-b dw}Load%{+b dk}:%{-b dg}%l %{+b dk}] [%{-b dg}%2`%{+b dk}] %=[ %{-b dg}%1`%{=b dk} ]%{-b dw}:%{+b dw}:%&lt;"\n\nsorendition "-b dw"\n[roel@roel ~]$ cat ~/scripts/meminfo\n#!/bin/sh\nRAM=`cat /proc/meminfo | grep "MemFree" | awk -F" " \'{print $2}\'`\nSWAP=`cat /proc/meminfo | grep "SwapFree" | awk -F" " \'{print $2}\'`\necho -n "${RAM}kb/ram ${SWAP}kb/swap"\n[roel@roel ~]$\n</code></pre>\n'}, {'answer_id': 70985, 'author': 'Andrew Johnson', 'author_id': 5109, 'author_profile': 'https://Stackoverflow.com/users/5109', 'pm_score': 4, 'selected': False, 'text': '<p>You can remap the escape key from <kbd>Ctrl</kbd> + <kbd>A</kbd> to be another key of your choice, so if you do use it for something else, e.g. to go to the beginning of the line in bash, you just need to add a line to your ~/.screenrc file. To make it ^b or ^B, use:</p>\n\n<pre><code>escape ^bB\n</code></pre>\n\n<p>From the command line, use names sessions to keep multiple sessions under control. I use one session per task, each with multiple tabs:</p>\n\n<pre>\n  screen -ls         # Lists your current screen sessions\n  screen -S &lt;name&gt;   # Creates a new screen session called name\n  screen -r &lt;name&gt;   # Connects to the named screen sessions\n</pre>\n\n<p>When using screen you only need a few commands:</p>\n\n<pre>\n  ^A c          Create a new shell\n  ^A [0-9]      Switch shell\n  ^A k          Kill the current shell\n  ^A d          Disconnect from screen\n  ^A ?          Show the help\n</pre>\n\n<p>An excellent quick reference can be found <a href="http://aperiodic.net/screen/quick_reference" rel="nofollow noreferrer">here</a>. It is worth bookmarking.</p>\n'}, {'answer_id': 71055, 'author': 'dummy', 'author_id': 6297, 'author_profile': 'https://Stackoverflow.com/users/6297', 'pm_score': 0, 'selected': False, 'text': '<p>^A A switches back to the screen you just came from.</p>\n'}, {'answer_id': 106158, 'author': 'jkramer', 'author_id': 12523, 'author_profile': 'https://Stackoverflow.com/users/12523', 'pm_score': 2, 'selected': False, 'text': '<p>Not really essential not solely related to screen, but <a href="https://web.archive.org/web/20130313011037/http://www.frexx.de/xterm-256-notes/" rel="nofollow noreferrer">enabling 256 colors in my terminal, GNU Screen and Vim</a> improved my screen experience big time (especially since I code in Vim about 8h a day - there are some great eye-friendly colorschemes).</p>\n'}, {'answer_id': 117008, 'author': 'innaM', 'author_id': 7498, 'author_profile': 'https://Stackoverflow.com/users/7498', 'pm_score': 2, 'selected': False, 'text': '<p>I like to set up a screen session with descriptive names for the windows. ^a A will let you give a name to the current window and ^a " will give you a list of your windows.\nWhen done, detach the screen with ^a d and re-attach with screen -R</p>\n'}, {'answer_id': 117072, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 3, 'selected': False, 'text': '<p><a href="http://www.debian-administration.org/articles/34" rel="noreferrer">http://www.debian-administration.org/articles/34</a></p>\n\n<p>I wrote that a couple of years ago, but it is still a good introduction that gets a lot of positive feedback.</p>\n'}, {'answer_id': 157174, 'author': 'Zsolt Botykai', 'author_id': 11621, 'author_profile': 'https://Stackoverflow.com/users/11621', 'pm_score': 3, 'selected': False, 'text': '<p>I "must" add this: add</p>\n\n<pre><code>bind s\n</code></pre>\n\n<p>to your <code>.screenrc</code>, if You - like me - used to use split windows, as <code>C-a S</code> splits the actual window, but <code>C-a s</code> freezes it. So I just disabled the freeze shortcut.</p>\n'}, {'answer_id': 563876, 'author': 'David Dean', 'author_id': 67829, 'author_profile': 'https://Stackoverflow.com/users/67829', 'pm_score': 2, 'selected': False, 'text': '<p>There is some <a href="http://blog.dustinkirkland.com/2008/12/ubuntu-server-includes-window-manager.html" rel="nofollow noreferrer">interesting work</a> being done on getting a good GNU screen setup happening by default in the next version of Ubuntu Server, which includes using the bottom of the screen to show all the windows as well as other useful machine details (like number of updates available and whether the machine needs a reboot). You can probably grab their <code>.screenrc</code> and customise it to your needs.</p>\n\n<p>The most useful commands I have in my <code>.screenrc</code> are the following:</p>\n\n<pre><code>shelltitle "$ |bash" # Make screen assign window titles automatically\nhardstatus alwayslastline "%w" # Show all window titles at bottom line of term\n</code></pre>\n\n<p>This way I always know what windows are open, and what is running in them at the moment, too.</p>\n'}, {'answer_id': 894140, 'author': 'Gary Chambers', 'author_id': 103072, 'author_profile': 'https://Stackoverflow.com/users/103072', 'pm_score': 2, 'selected': False, 'text': "<p>The first modification I make to .screenrc is to change the escape command.  Not unlike many of you, I do not like the default Ctrl-A sequence because of its interference with that fundamental functionality in almost every other context.  In my .screenrc file, I add:</p>\n\n<p>escape `e</p>\n\n<p>That's backtick-e.</p>\n\n<p>This enables me to use the backtick as the escape key (e.g. to create a new screen, I press backtick-c, detach is backtick-d, backtick-? is help, backtick-backtick is previous screen, etc.).  The only way it interferes (and I had to break myself of the habit) is using backtick on the command line to capture execution output, or pasting anything that contains a backtick.  For the former, I've modified my habit by using the BASH $(command) convention.  For the latter, I usually just pop open another xterm or detach from screen then paste the content containing the backtick.  Finally, if I wish to insert a literal backtick, I simply press backtick-e.</p>\n"}, {'answer_id': 1236687, 'author': 'staticsan', 'author_id': 28832, 'author_profile': 'https://Stackoverflow.com/users/28832', 'pm_score': 3, 'selected': False, 'text': "<p>Some tips for those sorta familiar with screen, but who tend to not remember things they read in the man page:</p>\n\n<ul>\n<li>To change the name of a screen window is very easy: <kbd>ctrl</kbd>+<kbd>A</kbd> <kbd>shift</kbd>+<kbd>A</kbd>. </li>\n<li>Did you miss the last message from screen? <kbd>ctrl</kbd>+<kbd>a</kbd> <kbd>ctrl</kbd>+<kbd>m</kbd> will show it again for you.</li>\n<li>If you want to run something (like tailing a file) and have screen tell you when there's a change, use <kbd>ctrl</kbd>+<kbd>A</kbd> <kbd>shift</kbd>+<kbd>m</kbd> on the target window. Warning: it will let you know if <em>anything</em> changes.</li>\n<li>Want to select window 15 directly? Try these in your <code>.screenrc</code> file:</li>\n</ul>\n\n<blockquote>\n<pre><code>bind  ! select 11\nbind  @ select 12\nbind \\# select 13\nbind  $ select 14\nbind  % select 15\nbind \\^ select 16\nbind  &amp; select 17\nbind  * select 18\nbind  ( select 19\nbind  ) select 10\n</code></pre>\n</blockquote>\n\n<p>That assigns <kbd>ctrl</kbd>+<kbd>a</kbd> <kbd>shift</kbd>+<kbd>0 through 9</kbd> for windows 10 through 19.</p>\n"}, {'answer_id': 1680589, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 2, 'selected': False, 'text': '<p>I use the following for <code>ssh</code>:</p>\n\n<pre><code>#!/bin/sh\n# scr - Runs a command in a fresh screen\n#\n# Get the current directory and the name of command\n\nwd=`pwd`\ncmd=$1\nshift\n\n# We can tell if we are running inside screen by looking\n# for the STY environment variable.  If it is not set we\n# only need to run the command, but if it is set then\n# we need to use screen.\n\nif [ -z "$STY" ]; then\n        $cmd $*\nelse\n        # Screen needs to change directory so that\n        # relative file names are resolved correctly.\n        screen -X chdir $wd\n\n        # Ask screen to run the command\n        if [ $cmd == "ssh" ]; then\n                screen -X screen -t ""${1##*@}"" $cmd $*\n        else\n                screen -X screen -t "$cmd $*" $cmd $*\n        fi\nfi\n</code></pre>\n\n<p>Then I set the following bash aliases:</p>\n\n<pre><code>vim() {\n        scr vim $*\n}\n\nman() {\n        scr man $*\n}\n\ninfo() {\n        scr info $*\n}\n\nwatch() {\n        scr watch $*\n}\n\nssh() {\n        scr ssh $*\n}\n</code></pre>\n\n<p>It opens a new screen for the above aliases and iff using ssh, it renames the screen title with the ssh hostname.</p>\n'}, {'answer_id': 4651572, 'author': 'bambams', 'author_id': 149184, 'author_profile': 'https://Stackoverflow.com/users/149184', 'pm_score': 1, 'selected': False, 'text': '<p>I like to use <code>screen -d -RR</code> to automatically create/attach to a given screen. I created bash functions to make it easier...</p>\n\n<pre><code>function mkscreen\n{\n    local add=n\n\n    if [ "$1" == \'-a\' ]; then\n        add=y\n        shift;\n    fi\n\n    local name=$1;\n    shift;\n    local command="$*";\n\n    if [ -z "$name" -o -z "$command" ]; then\n        echo \'Usage: mkscreen [ -a ] name command\n\n    -a          Add to .bashrc.\' 1&gt;&amp;2;\n        return 1;\n    fi\n\n    if [ $add == y ]; then\n        echo "mkscreen $name $command" &gt;&gt; $HOME/.bashrc;\n    fi\n\n    alias $name="/usr/bin/screen -d -RR -S $name $command";\n\n    return 0;\n}\n\nfunction rmscreen\n{\n    local delete=n\n\n    if [ "$1" == \'-d\' ]; then\n        delete=y\n        shift;\n    fi\n\n    local name=$1;\n\n    if [ -z "$name" ]; then\n        echo \'Usage: rmscreen [ -d ] name\n\n    -d          Delete from .bashrc.\' 1&gt;&amp;2;\n        return 1;\n    fi\n\n    if [ $delete == y ]; then\n        sed -i -r "/^mkscreen $name .*/d" $HOME/.bashrc;\n    fi\n\n    unalias $name;\n\n    return 0;\n}\n</code></pre>\n\n<p>They create an alias to <code>/usr/bin/screen -d -RR -S $name $command</code>. For example, I like to use irssi in a screen session, so in my .bashrc (beneath those functions), I have:</p>\n\n<pre><code>mkscreen irc /usr/bin/irssi\n</code></pre>\n\n<p>Then I can just type <code>irc</code> in a terminal to get into irssi. If the screen \'irc\' doesn\'t exist yet then it is created and /usr/bin/irssi is run from it (which connects automatically, of course). If it\'s already running then I just reattach to it, forcibly detaching any other instance that is already attached to it. It\'s quite nice.</p>\n\n<p>Another example is creating temporary screen aliases for perldocs as I come across them:</p>\n\n<pre><code>mkscreen perlipc perldoc perlipc\nperlipc # Start reading the perldoc, ^A d to detach.\n...\n# Later, when I\'m done reading it, or at least finished\n# with the alias, I remove it.\nrmscreen perlipc \n</code></pre>\n\n<p>The -a option (must be first argument) appends the screen alias to .bashrc (so it\'s persistent) and -d removes it (these can potentially be destructive, so use at own risk). xD</p>\n\n<p>Append:</p>\n\n<p>Another bash-ism that I find convenient when working a lot with screen:</p>\n\n<pre><code>alias sls=\'/usr/bin/screen -ls\'\n</code></pre>\n\n<p>That way you can list your screens with a lot fewer keystrokes. I don\'t know if <code>sls</code> collides with any existing utilities, but it didn\'t at the time on my system so I went for it.</p>\n'}, {'answer_id': 15283793, 'author': 'user2146463', 'author_id': 2146463, 'author_profile': 'https://Stackoverflow.com/users/2146463', 'pm_score': 0, 'selected': False, 'text': '<p><kbd>Ctrl</kbd> + <kbd>A</kbd> is a great special character for Unix people, but if you\'re using screen to talk to <a href="https://en.wikipedia.org/wiki/OpenVMS" rel="nofollow noreferrer">OpenVMS</a>, then not being able to ^A is going to make you bald prematurely.</p>\n\n<p>In <a href="https://en.wikipedia.org/wiki/OpenVMS#Origin_and_name_changes" rel="nofollow noreferrer">VMS</a>, if you\'re editing a <a href="https://en.wikipedia.org/wiki/DIGITAL_Command_Language" rel="nofollow noreferrer">DCL</a> command prior to execution from the history buffer, Insert mode is off (it has to be for a few reasons I won\'t get into here) ... to turn it on so you don\'t over-type your command rather than space things out, you have to hit `^A.</p>\n'}]
['https://Stackoverflow.com/questions/70614', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/6414/']