For many people, the Linux terminal represents a substantial portion of where their most important work happens. Whether a system administrator managing multiple remote machines, a programmer trying to run a new snippet of code as they walk through the source, or simply an ordinary user who is trying to read a man page for documentation as they step through pecking out a lengthy command, it's not uncommon to need to run and see the output of multiple terminal applications at a time.
Why should keeping track of multiple applications be a difficult proposition that requires a fancy modern GUI? Sure, you can launch multiple terminal instances, or use a terminal emulator that tiles terminals for you. But there's an easier, and arguably better way, by using a native terminal application to manage your multiple applications just like you would in a traditional windowed environment. Enter tmux, the terminal multiplexer.
Before we get to tmux and why it will change the way you interact with the command line, let's talk a bit about processes. When you launch a program from the terminal, it may seem like your terminal is now entirely consumed by that process. But that's not actually the case. In a Bash shell (and many others) you can send your application to the background either at launch (by placing a & at the end of the command) or by pressing ctrl+z to suspend the job and then sending your command to the background with bg, and returning it with fg, or view a list of jobs with the jobs command.
Process control is itself an important concept in the Linux world, one that any Linux user would benefit from taking a little time to understand, but it's a big enough area to be beyond the scope of this article. I mention it here because it's a common misconception of newcomers that launching a command at the command line always “ties up” the terminal that launched it until the process is terminated, which isn't the case.
There are many problems that tmux can help solve, but the primary purpose is to allow you to run several applications within the same terminal window, either side-by-side or allowing you to easily switch between applications, or groups of applications together in the same window, with a simple keystroke. It also allows you “attach” or “detach” from a tmux instance, in effect, keeping your applications running just like you left them if you close your terminal, allowing you to come back later.
Installing tmux is easy. If it's not already on your machine, it's also certainly in your Linux distribution's default repositories, so installation with your package manager of choice will be simple. On Fedora, that means a simple $ sudo dnf install tmux -y will install it for you and you'll be ready to get up and running in seconds.
Once you've installed and launched tmux for the first time, you'll see a green bar at the bottom of your terminal. By default, the bar will give you a list of your open windows, your hostname, and the time, but you can configure it to show much more.
Commands in tmux are issued by first issuing a command prefix. By default, this is ctrl+b, but you can change this as well. After pressing ctrl+b, you can then create a new window by pressing the c key. You can then issue commands in this new window, and switch back to your original window by pressing p for the previous window, or w to list all of the windows you have created, from which you can jump between them.
You can also split a window into multiple panes by pressing ctrl+b or whatever you have assigned your command prefix to be, and then either % to split the screen vertically or " to split it horizontally. You can then jump between panes with your prefix and the arrow keys.
Those are the basics. When you're done using a pane or window, you can remove it with your command prefix and x for a pane or & for a window. Want to learn more? The prefix followed by ? will tell you quite a bit more; it's the built-in command list.
Once you've started using tmux, explored these basic commands, and begun to set up a terminal environment customized to your needs, you'll want to move beyond the basic instructions I've included here. And well you should—there's a lot of great information out there! Here are a few other resources I've found helpful:
Go read the man page. Seriously, there's a reason that man pages exist, even in the modern world of search-enabled everything. The man page will always be there at your fingertips, Internet access or not. It will tell you all of the basics that you need to know.
Take a look at another guide that details how other people are using and configuring tmux to meet their needs. Here are a few good ones. Then, go take a look at your .tmux.conf file your home directory, where you can customize tmux in great detail. Here's a good guide for that.
Read a book. Two of better I've found include tmux 2: Productive Mouse-Free Development, available in paper or as an ebook from Pragmatic Press, and The Tao of tmux, which in addition to the paper or ebook versions is also available to read online for free under a CC BY-NC-SA 3.0 license.
Join a community. Reddit has a r/tmux group, most Linux user groups will have at least one other tmux user who's willing to help you, and the #tmux channel on Freenode IRC is usually full of hundreds of helpful people.
Is tmux the only tool out there which provides this functionality? As is often the case in the open source world, the answer is no! GNU Screen is another popular tool providing similar functionality. While there are some subtle difference between GNU Screen and tmux, which one you choose to use is really a matter of individual preference. GNU Screen is decades old and very stable; the flip side of its age is that it hasn't seen nearly as much active development.
And while greybeards and other old-timers might be perfectly happy GNU Screen, tmux seems to have wider interest among the broader Linux community these days. That doesn't make it better or worse, but it does mean that I've found it's often easier to find someone who has already solved my exact problem or configuration challenge when looking around support communities and the Internet. Its unique name also makes tmux a lot easier to find plugins for when looking around GitHub and other software repositories, too.
Do you use tmux? What do you wish you had known when you were getting started? Let us know in the comments below.