Linux tip: Using multiple terminals with byobu
Move over screen, a better terminal multiplexer is here.
This excerpt is from the book, Ubuntu Unleashed: 2013 Edition by Matthew Helmke, published by Pearson/SAMS, Dec 2012, ISBN 0672336243; copyright 2013 by Pearson Education, Inc. For more info please visit www.informit.com/title/0672336243
[ Enter ITworld's drawing to win a copy of Ubuntu Unleashed: 2013 Edition ]
Many Linux veterans have enjoyed and use the
screen command, which was designed to enable you to use one terminal to control several terminal sessions easily. Although
screen has been a welcome and useful tool, a better one has appeared called
byobu; it is an enhanced version of
screen. Byobu is a Japanese term for decorative, multipanel, vertically folding screens that are often used as room dividers.
Picture this scene: You connect to a server via Secure Shell (SSH) and are working at the remote shell. You need to open another shell window so you can have the two running side by side; perhaps you want the output from top in one window while typing in another. What do you do? Most people would open another SSH connection, but that is both wasteful and unnecessary. Like
byobu is a terminal multiplexer, which is a fancy term for a program that enables you to run multiple terminals inside one terminal.
The best way to learn
byobu is to try it yourself. So, open a console, type
byobu, and then press Enter. Your display blinks momentarily and is then replaced with a new console with new information in a panel at the bottom. Now, do something with that terminal. Run
top and leave it running for the time being. Press F2. Your prompt clears again, leaving you able to type. Run the
Pop quiz: What happened to the old terminal running
top? It is still running, of course. You can press F3 to return to it. Press F4 to go back to your
uptime terminal. While you are viewing other terminals, the commands in the other terminals carry on running as normal so you can multitask. Here are some of the basic commands in
F2—Create a new window
F3—Go to the previous window
F4—Go to the next window
F9—Open the Byobu menu for help and configuration
To close a terminal within
byobu, simply log out of it normally using
exit or Ctrl+D. When you exit the last terminal session that is open in
byobu, the program closes as well and drops you to the regular terminal session you used to start
However, there are two alternatives to quitting a
byobu session: locking and disconnecting. The first, activated with F12, locks access to your screen data until you enter your system password.
The second is the most powerful feature of
screen and also works beautifully in
byobu: You can exit it and do other things for a while and then reconnect later; both
byobu pick up where you left off. For example, you could be typing at your desk, detach from a session and go home, reconnect, and carry on as if nothing had changed. What’s more, all the programs you ran from
byobu carry on running even while
byobu is disconnected. It even automatically disconnects for you if someone closes your terminal window while it is in a locked state (with Ctrl+A+X).
To disconnect, press F6. You are returned to the prompt from which you launched
byobu and can carry on working, close the terminal you had opened, or even log out completely. When you want to reconnect, run the command
screen -R or
byobu -R. You can, in the meantime, just run
byobu and start a new session without resuming the previous one, but that is not wise if you value your sanity. You can disconnect and reconnect the same session as many times you want, which potentially means you need never lose your session again.
Although this has been a mere taste of what
screen can do, hopefully you can see how useful they can be. Check the man pages for each to learn more.