Whether you’re new to the command line or just dipping your toes into the power of tmux, one thing that stumps almost everyone at first is how to exit safely. You’ve opened a session, done your thing, and now you’re left wondering, “How do I get out without breaking something?” Don’t worry — this guide will walk you through it step-by-step, and make the journey fun too!
TL;DR
To exit tmux safely, you can either detach from it or close it completely. Use Ctrl+b followed by d to detach — your session stays alive in the background. If you’re done, just type exit in all panes to close it fully. Or use Ctrl+b then :kill-session for a quick goodbye.
What Is Tmux?
Tmux is a terminal multiplexer. Imagine it like a TV that can show multiple channels at once. You can split your screen, run multiple commands, and jump around — all inside your terminal.
If you’ve ever thought, “I wish I could keep my work running even if I disconnect from the server,” tada! Tmux is your new best friend.
Why Not Just Press Ctrl+C?
Good question.
Pressing Ctrl+C shuts down the current command. Sometimes, that’s what you want. Other times, it can leave things hanging or cause data loss if you’re in the middle of something important.
So instead of just hoping for the best, let’s learn safe ways to close or leave tmux.
The Two Ways to Exit Tmux
There are two main ways to leave tmux:
- Detach — Leave the session running in the background
- Exit — Quit the session completely and close it
Option 1: Detach
This is the most common move. Detaching means you ‘step out’ but don’t close anything. Your session keeps running, and you can reconnect later.
Here’s how to do it:
Ctrl + b, then d
That’s it! Hold Ctrl, press b, release both, then press d.
You’ll see a message like:
[detached (from session xyz)]
Now you’re back in your regular terminal. The tmux session is still running in the background.
To reattach later:
tmux attach
If you have multiple sessions:
tmux ls # Lists all sessions
tmux attach -t session_name
Option 2: Exit
Done with your work and want to shut it all down? Easy!
In each pane or window, type:
exit
Once you exit the last shell, tmux will automatically close the session.
Too many panes? Here’s a faster way:
Ctrl + b, then :
Typekill-sessionand hitEnter.
Boom. All gone. Clean and safe.
Bonus Tips!
Kill All Sessions
Have lots of active sessions and just want to nuke them?
tmux kill-server
This will close every tmux session. Use with care!
Saving Your Session
If you want your session to keep running (maybe you launched a long build), detach instead of exiting. Later, come back and resume where you left off.
Quitting a Specific Window or Pane
Inside tmux, you might have split windows or multiple tabs. To quit one of them:
exit
This will only close that one shell pane. The rest of the session stays alive.
Check What’s Happening
Not sure what sessions are active? Run:
tmux ls
To close a specific one:
tmux kill-session -t session_name
Troubleshooting
I Typed “exit,” but I’m Still Stuck!
You may have more than one pane open. You need to exit all of them.
I Detached, But Now I Can’t Find My Session!
Use this:
tmux ls
Then attach using the session name listed.
I Accidentally Closed My Terminal!
No worries. If you detached or your session wasn’t yet shut down, you can jump right back in.
tmux attach
It’s like having digital superpowers, right?
Quick Reference Guide
- Detach:
Ctrl + bthend - Exit: type
exitin each pane - Force quit:
Ctrl + bthen:kill-session - List sessions:
tmux ls - Attach to a session:
tmux attachortmux attach -t name - Kill all sessions:
tmux kill-server
Wrapping Up
Exiting tmux doesn’t have to feel like escaping a locked room. Once you remember Ctrl + b then d, or simply typing exit, you’ll be a tmux ninja in no time!
Use detach when you want to take a break and come back. Use exit or kill-session when you’re saying goodbye for good.
Peace out, terminal master! Have fun in your adventures with tmux!
