How to kill all tmux sessions?

Quick Answer

To kill all tmux sessions, use tmux kill-server. If you want to kill all sessions except the current one, use tmux kill-session -a.

$ tmux kill-server

Detailed Explanation

tmux organizes your terminal sessions hierarchically. When you need to clean up and remove all sessions at once, there are several approaches you can take depending on your specific needs.

Kill all tmux sessions (including the server):

The most direct way to kill all tmux sessions is to terminate the entire tmux server:

$ tmux kill-server

This command immediately terminates the tmux server along with all running sessions, windows, and panes. Use this with caution as you'll lose all unsaved work in any applications running inside tmux.

Kill all sessions except the current one:

If you're already attached to a tmux session and want to keep only that one while terminating all others:

$ tmux kill-session -a

Kill all sessions except a specific one:

To kill all sessions except a named session (e.g., "dev"):

$ tmux kill-session -a -t dev

Using shell commands to kill all sessions:

If you prefer a more selective approach, you can list all sessions and then kill them using shell scripting:

$ for session in $(tmux list-sessions -F '#{session_name}'); do
    tmux kill-session -t "$session"
done

Warning

Killing all tmux sessions will terminate all running programs within those sessions. Make sure to save your work and close applications properly before using these commands.

Pro Tip

If you frequently need to manage sessions, consider adding custom key bindings to your .tmux.conf:

# Kill all other sessions
bind X confirm-before -p "kill other sessions? (y/n)" "kill-session -a"