Learn the basics of GNU Screen terminal multiplexing technology, and then download our terminal command cheat sheet so you can familiarize yourself with common shortcuts.
For the average user, the command line terminal window can be confusing and mysterious. But as you become more familiar with the Linux terminal, you'll 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 to interact with each application is a keyboard. 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 then being able 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 in the terminal, allowing multiple screen windows to be displayed 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 graphical desktop environments. 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 the key bindings are designed for common terminal sequences, making them convenient.
There are two popular multiplexers: tmux and GNU Screen. Although they interact with them in slightly different ways, 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, 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 will appear to have nothing except the default prompt. Of course, your other terminal still exists; it's just hiding behind the new window. To navigate through the open windows, press Ctrl+A
, release, and then press n
(for next) or p
(for previous). In the case of only two open windows, 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 use GNU Screen because you like multitasking, focusing on one window at a time 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
, then use Tab
to move into the split window. Once inside, use Ctrl+A
, then n
to browse 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
, then |
(which 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 (called "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 a reminder of 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 don't use often may be difficult to remember. You can access the GNU Screen help interface by pressing Ctrl+A
, 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]