Tmux is one of the most useful tool when it comes to using using a linux terminal.
Tmux is a terminal multiplexer, it allows a user to access multiple terminals (or windows), each running a separate program, while providing a single screen to work on. Tmux is useful for running more than one command-line program at the same time, increasing productivity and the way you work. Before we delve into the details, you can explore an Introduction to Tmux to get started and make yourself familiar with the basics.
Let’s say you have already created one or more tmux sessions, and you have exited from it. So, basically you are in your default command prompt or shell (ex- Bash or Zsh or Fish. We will discuss how you will connect or re-attach or attach back to the tmux session that you have disconnected or exited from.
Attach to a Tmux Session
Let’s consider the case where you will have created multiple sessions and detached from them.
tmux new -s dev-session
Ctrl-B, d # Detach from session
tmux new -s prod-session
Ctrl-B, d Detach from session
To list all tmux sessions, you can run the command –
tmux ls
Now, you have 2 sessions dev-session
and prod-session
. You are now looking to connect back to the dev-session
.
tmux attach -d -t dev-session
You can also connect by the session id that you’ll see as output when you run the tmux ls
command-
tmux attach -d -t 0
Once connected or attached, you can disconnect from the session using the tmux detach shortcut. You can also switch between sessions using the tmux switch session shortcut.
I hope you found this article useful, glad that you found it easy to connect back to a session in Tmux. You can also check out the complete tmux cheatsheet of keyboard shortcuts and mouse shortcuts.
As a developer, I have come to value tools that increase my efficiency and productivity – checkout tmux cheatsheet. One such tool that I cannot do without is Tmux. It’s a game-changer for me, providing the ability to run multiple terminal sessions within one window or even from one session. What I love about Tmux is that it allows me to create, detach, and reattach sessions without a hitch. This means I can run long processes or manage servers seamlessly. I find its minimalist design and efficiency incredibly appealing.