Splitting a Linux console with tmux

In watching the Julian Assange movie Fifth Estate:


I noticed that he used what looked like a Linux console that had several external programs loaded:


Knowing what I now know about Linux, I immediately thought:

  1. I could probably whip up something like that in Python using Curses.
  2. Wait, this is Linux, this must already exist.
  3. But wait, these are “tv hackers”, they might be using ImaginaryOS v5.0 so maybe it doesn’t exist?!

Introducing TMux (terminal multiplexer):
I never did find exactly what they used in the movie, but I found something pretty cool instead – and that is “tmux”, the replacement for “screens”:

$ sudo apt-get install tmux

This is basically a program that lets you manage multiple “sessions” which you can switch back-and-forth between – and it lets you split up one window into several panes, all which are sizable too.

Why do you need this?
Well, you probably don’t “need” it, because you can certainly have multiple SSH sessions open:


or if you are logged into Linux, you can have multiple tabs open:


however, many times you need to constantly switch back and forth between the tabs, which can be annoying. For example, what if you want to monitor the latest messages to syslog:

$ tail /var/log/syslog –f

that constantly monitors file for changes and keeps spitting out the new messages to the screen until you hit CTRL+C. So again, you could do something in one screen and then check back on this tab, but if you are doing a bunch of tasks it might be easier to do it on one screen.

Let me create a simpler, reproducible example. Let’s say I want to monitor the dpkg.log which keeps track of when software is installed and uninstalled. Start up tmux:

$ tmux

you’ll still see a console screen, but you’ll notice a status bar at the bottom (I’ve customized mine, more on that below):


From here we can split the current view horizontally (CTRL+B, “) or vertically (CTRL+B, %) – I’ll do horizontally:


now in the bottom pane, I want to have that take up less space, so I’ll do CTRL+B and then a “:” to see this prompt at the bottom:


in there, I type:

resize-pane -D 10

which means resize the current pane Down by 10 lines, which now makes the window look like this:


so now, in the bottom window, I want to monitor what happens with dpkg, so I run:

$ tail /var/log/dpkg.log –f

the –f means keep monitoring the file and spit up new lines as they come in. This makes the bottom pane kind of like a “status” window as I install things. To get back up to the top pane, do CTRL+B and then up arrow.

From there, I can install and uninstall software, and watch the log messages scroll in the bottom pane:


Or may you want to go a little crazier and monitor several things at once by splitting the screen into more panes:


In the case above, I split the top window into two, then in the right pane, I split that horizontally. In the top-right, you can do CTRL+B, T to show the time, then below that I’m running “htop”, and in the bottom pane I’m monitoring /var/log/syslog.

$ tail /var/log/syslog -f

As you can imagine, the configurations are endless, so if you don’t want to keep switching back-and-forth between tabs, that can be a useful tool.

Basic Usage:
There are many detailed posts written up on this, but some of this was difficult to figure out, so I thought I’d write some of it here, here is what I seem to use pretty constantly:

Keyboard Shortcut Description
CTRL+B The key sequence you have to do before doing anything else, then let go and do the next sequence. (C+B)
(C+B),“ Split the current pane into top and bottom.
(C+B), % Split the current pane into left and right.
(C+B), up down left right Go the closest pane above, below, left, or right. Only one move per key sequence!
(C+B), : Get to the command-input line. (:)
(:) resize-pane –U 20 Resizes the current pane –U, –D, –L, –R (up down left right) by 20 cells.

also, you can can do quite a bit with the look/feel of it, and the status bar, by configuring a ~/.tmux.config file. I published mine, as seen above, here:


just copy all 3 of those files to your home directory and tmux should pick them up.

Posted in Computers and Internet, General, Infrastructure, Linux, Uncategorized

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.


Enter your email address to follow this blog and receive notifications of new posts by email.

Join 9 other followers

%d bloggers like this: