Learn the basics of GNU Screen terminal multiplexing technology, and then download our terminal command cheat sheet to familiarize yourself with common shortcuts.
For the average user, the command line terminal window can be confusing and mysterious. But as you gain further understanding of the Linux terminal, you will quickly realize its efficiency and power. However, it won't take long before you want to make the terminal even more efficient. Besides having more terminals in your terminal, what other ways are there to improve your terminal efficiency?
Terminal Multiplexing#
One of the many advantages of the terminal is that it is a centralized control interface. It is a window that allows you to access hundreds of applications, and all you need is a keyboard to interact with each application. However, modern computers almost always have excess processing power, and modern computer experts like to multitask, which limits the ability of a window to handle hundreds of applications.
The common answer to this problem is terminal multiplexing: stacking virtual terminals together and the ability to move between them. With a terminal multiplexer, you maintain centralized control, but when you multitask, you can switch terminals. Even better, you can split the screen within a terminal to display multiple screen windows at the same time.
Choosing the Right Multiplexer#
Some terminals offer similar functionality with tabbed interfaces and split views, but there are subtle differences. First, these terminal features depend on a graphical desktop environment. Second, many graphical terminal features require mouse interaction or use inconvenient keyboard shortcuts. Terminal multiplexers work just as well on text consoles as they do on graphical desktops, and their key bindings are designed for common terminal sequences, making them convenient.
There are currently two popular multiplexers: tmux and GNU Screen. Although you interact with them slightly differently, they do the same thing and have mostly the same features. This article is an introductory guide to GNU Screen. For an introduction to tmux, please read Kevin Sonney's tmux introduction.
Using GNU Screen#
The basic usage of GNU Screen is simple. Start it with the screen
command, and you will enter the first window of the Screen session. You may not notice any changes until you decide you need a new terminal prompt.
When a terminal window is occupied by some activity (such as starting a text editor like Vim or Jove, or working with audio/video, or running batch tasks), you can create a new window. To open a new window, press Ctrl+A
, release it, and then press c
. This will create a new window based on your existing window.
You will know that you are in a new window because your terminal appears to have nothing except the default prompt. Of course, your other terminal is still there, it's just hiding behind the new window. To navigate through the open windows, press Ctrl+A
, release it, and then press n
(for next) or p
(for previous). In the case of having only two windows open, n
and p
have the same functionality, but you can open more windows at any time (Ctrl+A
, then c
), and switch between them.
Splitting the Screen#
The default behavior of GNU Screen is more like a mobile device screen than a desktop: you can only see one window at a time. If you are using GNU Screen because you like multitasking, focusing on only one window may seem like a step back. Fortunately, GNU Screen allows you to divide the terminal into windows within windows.
To create a horizontal split window, press Ctrl+A
, and then press s
. This will place one window on top of another, like a pane. However, the split space is useless until you tell it what to display. Therefore, after creating a split window, you can use Ctrl+A
and then use Tab
to move into the split window. Once inside, use Ctrl+A
and then n
to browse through all available windows until the content you want to display appears in the split pane.
You can also create a vertical split window by pressing Ctrl+A
and then pressing |
(this is a pipe character, obtained by pressing the shift
key and \
on most keyboards).
Customizing GNU Screen#
GNU Screen uses Ctrl+A
based shortcuts. Depending on your habits, this may feel very natural or very inconvenient, as you may use Ctrl+A
to move to the beginning of a line. Regardless, GNU Screen allows various customizations through the .screenrc
configuration file. You can use this to change the binding of the trigger key (known as "escape" key binding).
escape ^jJ
You can also add a status line to help you stay oriented in a Screen session.
# status bar, with current window highlighted
hardstatus alwayslastline
hardstatus string '%{= kG}[%{G}%H%? %1`%?%{g}][%= %{= kw}%-w%{+b yk} %n*%t%?(%u)%? %{-}%+w %=%{g}][%{B}%m/%d %{W}%C%A%{g}]'
# enable 256 colors
attrcolor b ".I"
termcapinfo xterm 'Co#256:AB=\E[48;5;%dm:AF=\E[38;5;%dm'
defbce on
In a session with multiple open windows, having an indicator that reminds you which windows have active focus and which windows have background activity can be particularly useful. It's like a task manager for the terminal.
Cheat Sheet#
When learning how to use GNU Screen, you need to remember many new keyboard commands. Some commands you will remember right away, but those commands you rarely use may be difficult to remember. You can access the GNU Screen help interface by pressing Ctrl+A
and then ?
.
Learning GNU Screen is a great way to improve your efficiency and agility with your favorite terminal emulator. Give it a try!
References#
Linux tips for using GNU Screen [1]
Tips for Using GNU Screen [2]