A quick introduction to tmux

Manage application windows in the terminal just like you would in a desktop window manager.
594 readers like this.
System statistics with sar and the /proc filesystem

ajmexico. Modified by Jason Baker. CC BY-SA 2.0.

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.

tmux-overview.png

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.

  • Print out or study a cheat sheet. There are plenty of options.

  • 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.

Jason Baker
Former Red Hatter. Now a consultant and aspiring entrepreneur. Map nerd, maker, and enthusiastic installer of open source desktop and self-hosted software.

6 Comments

Back in the 1970/80s, I worked on SCO/Unix and AIX systems, and we connected to the boxes using Wyse terminals. We had some software installed on systems which enabled you to do exactly what tmux did. You kicked it off and typed in your commands. If you proceeded the command with (I think) ctrl/shift/b, that put it on the second window, ctrl/shift/c the third etc. It was damned useful on dumb terminals, but I really can't see much of a need if you've got X, as the article says, just kick off another terminal.

Speaking of Wyse terminals, from memory the Wyse 60s were multi-session. Where I worked, one session connected you to the inhouse boxes and the other session to a dial up modem, which enabled you to connect to the client machines. I can't remember how we switched between sessions (probably by a low-tech rocker switch), but I do remember looking at the clients machine and then switching to an inhouse box running their software so we could determine what their problem was.

I am currently using tmux, setting up a server. One of the major 'features' I use, is the fact that you can leave a tmux session, while the job you started in this session, keeps running. Very handy although not always advised by other Linux experts.

I learned about GNU screen as a young sysadmin (whoa! I can let this long upgrade process run while I drive to the office?!). I've heard great things about tmux, but at this point my screen usage is fairly simple and everything is set just the way I like it. I haven't found something compelling enough to move me out of my rut to try tmux.

Locally, I always use 1 tmux session, and then other tabs in my graphical terminal emulator are either my current user in a different (or the same) directory, or connected to a remote machine through ssh, where I always run a tmux session (because my login user on the remote machine is under-privileged).

Good old technology I'm not missing missing much but was wonderful at some point in time (>20 years ago) when we only had one single 24x80 monochrome terminal to develop, debug and deploy software remotely using a 2400bps modem. We had up to 10 simultaneous terminal sessions we could switch back and forth, the difficulty was to remember where was what.
An other useful utility had been developed by one of our SW engineers from our UNIX SYSTEM IV development centers at Motorola; It was called "metoo". It was very useful for training and customer supports, that let multiple people share the same terminal session to their screen. So that's just the opposite of tmux :)

I love tmux. I use the sessions feature a lot. I usually have a session for each project I'm working on, and switch between them. It lets me have several projects in a single bash window. I also like to pair tmux with mosh, so I have a workspace that automatically resumes when I switch networks.

Creative Commons LicenseThis work is licensed under a Creative Commons Attribution-Share Alike 4.0 International License.