By Greg Rowe | July 30, 2018
Over the years I’ve spent thousands of hours working with devices
connected via serial ports. Only recently did I learn that the
GNU screen can be used as a terminal emulator.
has long been popular in the world of systems administration but
rarely do have I seen it used in the context of software development.
In the Windows world, years ago,
TeraTerm was a popular choice
among knowledgeable developers. It offered a lot more than the
Hyper Terminal application that shipped with MS
Windows. Then again almost any terminal emulator worked better than
Hyper Terminal. In more recent times putty,
the highly capable
ssh client for Windows gained popularity as a
Putty has become so popular that I’ve even seen
developers run it on Linux for the sole reason that they could master
a single tool for both Linux and Windows. If, however, you are
primarily working on Linux then I recommend the use of
screen can be frustrating. You’ll probably find yourself
asking things like “why isn’t ctrl-a working?” and “how do I exit
this?!“. If you are patient and work through the initial learning
curve you’ll reap rewards.
Launching screen as a terminal emulator is as easy as directing it to your serial port and telling it which baud rate to use. The example below is for a USB serial adapter.
screen /dev/ttyUSB0 115200
If you are an
emacs user or accustomed to bourne shells you’ll very
quickly become frustrated.
ctrl-a as an escape sequence
for sending commands to
screen itself rather than the end
terminal. This conflicts with default
emacs keybindings for
‘beginning of line’ which is also the default binding for ‘beginning
of line’ in a bourne shell or readline based application. You can
either get used to this or rebind the key to something else. I opt to
rebind the sequence since
emacs keybindings are permanently burned
into my brain.
To rebind edit
~/.screenrc with a new sequence. The sequence I chose
alt-shift-6 as it will not conflict with emacs.
# Make the escape sequence c-s-6 escape ^^^
I will not attempt to provide a
screen tutorial since there are many tutorials that do a far better job. Instead I will provide the key commands you’ll need to know and let you find your own journey in learning
screen in as much or as little detail as you desire.
At some point you’re going to want to exit
screen. To exit use
ESCAPE \ where
ESCAPE is whatever sequence you chose for
screen. In my case
ctrl-shift-6 \ exits
Inevitably you will want to look at output that scrolled past the
active window. Using the scroll bars will not work as you expect. This
screen keeps its own scroll back buffer. To scroll back
and (optionally) copy text use
ESCAPE esc. In my case that is
ctrl-shift-6 esc. You can then use your cursor keys to navigate the
history from the session.
One of the best features of screen is that you do not have to quit the
application. You can detach from a session and reattach at a later
time. A common case for this is doing work at your desk and then
continuing your debug session in a lab or at home. To detach press
ESCAPE d. In my case that is
With just a few commands you can be productive with
screen as a
- launch -
screen /dev/ttyUSB0 115200
- quit -
- detach -
- scroll -