Introduction to TMUX 😉

Krishan Shamod
3 min readSep 4, 2022

Let’s say you want to run a time-consuming task on your Linux server. For example, you’re copying a few gigabytes to another server. So you need to keep the SSH connection until it is finished. If not, the copying process will end without finishing it. In situations like this, there are few solutions. Today I’m going to show you how to handle a situation like this using tmux.

So what is tmux?

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.

Follow me 😎

1. First, install tmux on your server.

For Debian-based distributions,

sudo apt install tmux

For RedHat-based distributions,

sudo yum install tmux

2. Create a new session. So then you can run your tasks on this new session.

tmux new-session -s <SessionName>

Note: Replace <SessionName> with a meaningful session name.

You’re now in a new session and you can see the session name at the bottom. Each session can have more than one window and you’re in the default window which is number 0. You can see it next to the Session name.

3. Run your time-consuming task on this 0th window and detach the window. To detach it you need to press and release “ctrl + b” once and then you need to press “d”.

Now you can end the SSH connection without interrupting the running tasks on the new session. 😉

4. After some time connect to your server again and check the task status by attaching the session again.

tmux attach-session -t <SessionName>

5. Finally, you can end the session after finishing the task.

tmux kill-session -t <SessionName>

Extra tips 🤪

If you want to run multiple tasks then you can create new windows on the existing session. To do that first you need to press and release “ctrl + b” once and then you need to press “c”.

You can switch between windows by pressing and releasing “ctrl + b” once and then pressing “n”.

After finishing each task you can kill each window using this command. 🙃

tmux kill-window -t <WindowNumber>

Note: Replace <WindowNumber> with the window number you need to kill.

Thank you for reading and please let me know if there are any mistakes. 🫡

👉 Follow me on Twitter 🐦 for more updates 👈

--

--