Tmux: lower your stress level at work (or maybe also at home) using Tmux

Tmux: lower your stress level at work (or maybe also at home) using Tmux

In my job, I have to connect to many different servers. Fortunately, most of them are running Linux. So I connect to them, do whatever I have to do, and close the connection.

But sometimes, a terminal window isn't enough, because

  • I'd like to see what happens in a log file, while I'm typing my commands
  • Windows sorts terminal windows by start time. If I'm connected to different servers using PuTTY, they are not grouped by connection, and I can't just go around using ALT+TAB
  • most important: if my computer or my connection fails (especially when I'm in my home network, connected to VPN), I'll lose everything I've done before, or even worse: I don't know where it stopped and where I have to continue

But putting everything in background using nohup isn't a good solution - especially for jobs that have to be executed interactively.

A great solution is a terminal multiplexer like tmux. It creates one or more pages, shows us on which page we are, and which command is running on the other pages (tabs). Years before, I used screen, but tmux is much more comfortable.

tmux is a terminal multiplexer. It lets you switch easily between several programs in one terminal, detach them (they keep running in the background) and reattach them to a different terminal.

Installation

Installing tmux on Linux is quite easy. Depending on your Linux distribution, just run one of these:

  • apt install tmux
  • dnf install tmux
  • pacman -S tmux
  • zypper in tmux

Usage

Before you start your work, just run tmux, and you're ready to go:

If you want tmux to always start with you session, you could add it to your environment file of your shell, like .bashrc for bash, or .zshrc for zsh. But that would lead to always new session; the better way is to start a new session if there's no old one (like a new or a newly started system), or to use the one that already exists. So I used it like this:

if command -v tmux &> /dev/null && [ -z "$TMUX" ]; then
  tmux attach-session -t default || tmux new-session -s default
fi

Additional, you should know the most important shortcuts for the efficient usage of tmux:

  • Create a new tab: Control-b c (create)
  • Move to the next tab: Control-b n (next)
  • Move to the previous tab: Control-b p (previous)
  • Jump to a specific tab: Control-b [0..9]

What I really like is splitting a window:

  • Control-b " to split horizontally
  • Control-b % so split vertically
  • Control-b <arrow keys> to switch between the windows

If you want to learn more about tmux, see this Wiki page on GitHub.

Customization

If tmux fulfills your technical need, but find it's a little bit ugly, you can add themes.

Just go to the Github page of Oh my tmux! and install as described. After that, your console looks much better:

Subscribe to Martin's Blog

Don’t miss out on the latest issues. Sign up now to get access to the library of members-only issues.
jamie@example.com
Subscribe