- Published on
Learning tmux terminal multiplexer, a hacker's command line starter
- Lorenzo Pieri
Table of Contents
Have you ever wondered how those hackers in the movies look so cool? I mean, they are cool, you can't even blame a kid for wanting to become like them. But being cool is a drag, you know, because you gotta learn all that stuff before being actually able to use that.
But fret not, I welcome you with a new tutorial on, behold!, looking like a hacker without knowing deeps**t about what you are doing.
That's the movies' hackers.
By the way, if you are looking for some serious hacking you should definately check out Mr. Robot, tv show written with the help of cybersec specialists. I'm pretty sure a lot of you know about that, but for those late to the party, here is.
There's loads of softwares and hacking tools that you might want to checkout to become the scriptkiddie of the tales foretold, but before you do just that, maybe I could take you on a little joyride on the stolen knowledge of the great tinkerers.
Some people refer to it as a difficult and boring thing that could be done with other software, I, being one of the cool kids, call it
tmux is an amazing command line utility that can be used to multiplex your CLI environment to allow you to work on more concurrent windows and panes.
This tool also allows for session storage, so that you can save a CLI session and get back to it whenever you feel like you should (or have, if your boss is nagging you).
No more will you open 100s of command line windows (that's a lie, you will keep on doing it even if you master tmux because you are a sloth), from now on you will have the scepter of the One True Hacker.
The how (where the code is)
Table of Contents
tmux installation is pretty simple be it that you are on a macOS system or a Linux system. Cool pals get along just fine.
To install the
tmux terminal software all you need is an open command line, a keyboard and the following commands:
# for macOS users brew install tmux # for Linux distro users sudo apt-get install tmux # or you might be a Centos user yum install tmux
If you are not used to using commands on a terminal window, you might want to read An adventure to get started with the Unix Shell, part 1, a fairly simple post embarking the reader on a quest to pure command line knowledge! Should be fun.
Now that the installation, which was the hardest part, is done, we can move on to deploy the magical power of
tmux. How would we do that? Just
tmux the s**t out of your terminal.
# yep, that's about it, you are in the tmux tmux
"But nothing has changed, Lorenzo!", I can hear your whining from this distance.
It changed. What changes stays the same.
Now your tmux instance looks almost exactly like your previous terminal instance, but you might notice a small difference in the lower part of your window.
Something that might resemble
0:bash. In my terminal window I'm seeing
0:zsh, but that's because I'm using a different shell provider known as oh-my-zsh (Z shell).
That [number]:[value] tuple is the instantiated window of your tmux terminal.
tmux can spawn
panes that are shown in
windows that can be traversed and saved for later use as
Opening panes like a hacker
What we have in front of us is a
tmux window with one pane, but what we want to achieve is something like this:
Don't fret, that's just a bunch of really cool panes with really cool commands to make it look like I know what I'm doing (
cmatrix, htop, top). Let's start small.
2 panes, 1 window.
What you should know about
tmux is that any command processed by this application has to be prefixed by the sequence
CMD + B or
CTRL + B, depending on your system.
macOS users +
Anybody else +
I am aware that you already feel like Mozart playing your best ever Sonata, but there's still a lot more to go from here. That's just the entry point.
Now that we managed to have the big buttons appear to showcase the sequence of strokes you need to do to activate the tmux listener, I will continue the explanation using CMD, but you will always remember that CMD means CTRL for you non macOS users.
So, to open vertical panes you would press
Same process can be applied to the horizontal pane spawning process
As you might have noticed, the only change in keystrokes sequence is seen in the last character,
% and that is pretty much how you would deal all commands that tmux can understand.
Moving around panes like a hacker
So, you have spawned so many panes in a single window and you look cool to yourself, but not anybody else, and you also know why. Sure, spawning a lot of panes is for real, but now you gotta take control of that my friend.
Can you tell me which sequence of keystrokes would allow us to move around the panes? I'll tell you the first part, it's always CMD followed by B.
All you need is the rest, which amounts to
That's it, just arrows on a keyboard. Sweet pane movement achieved.
With what you learnt up to this point you can already create the same window I showed you a few paragraphs above.
Creating new windows of hacker's glory
But wouldn't it be nice if we could also divide our terminals in new windows. It would. That's also a pretty easy task once you know the last character. It's
and once the new window is created, you will notice on the far left corner that your :bash has now a new friend.
As with the panes, you can also move between windows with the sequence
+ + (or whatever number your window is)
To know the number of your window all you need to do is look at the bottom of your terminal.
Use cases, because imagination is key
That's it for a good start with the
tmux game up your toolbelt. You are now a knowledgable hackerman. You should also tell all your friends and show them your newfound power. So much for hard earned respect.
But being serious for just a moment, I can tell you that I have used tmux in many remote systems, especially during configuration. Say you have a file in
/etc/nginx but you also want to check your unix firewall while listing the files of a hosted website while doing other things like
systemctl and reading realtime logs.
Without tmux, that's a bummer but with
tmux it's a game changer.
You can start your terminal with tmux enabled from the start
# add the following lines to your ~/.bash_profile or .zsh if command -v tmux &> /dev/null && [ -z "$TMUX" ]; then tmux attach -t default || tmux new -s default fi # close and open the terminal again after
I hope you found this article useful and to your liking and if you have any requests, drop a message on one of my social media accounts or open an issue/start a discussion on github, on this repository!