DebugPointer
Published on

Attach to a Tmux session

Attach to a Tmux session

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.

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.

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.