How to kill all tmux sessions (or at least multiple sessions) from the (Ubuntu) CLI?
When I do ps aux | grep tmux
I see 3 processes:
UU 2970 0.0 0.0 19556 1228 pts/0 S+ 02:48 0:00 tmux
UU 3445 0.0 0.0 12944 988 pts/5 S+ 03:31 0:00 grep --color=auto tmux
UU 27557 0.0 0.2 29788 4840 ? Ss Jan04 0:02 tmux
How could I kill all of these at once (or at least some of them, selectivity) ?
You can use
tmux kill-server
to cleanly and gracefully kill all tmux open sessions (and server).If you are inside a tmux session you would like to keep, use
tmux kill-session -a
to close all other sessions.To close a specific session, use
tmux list-sessions
to identify the session you want to kill, and then usetmux kill-session -t targetSession
to kill that specific session.Also you can grossly kill all tmux processes with
pkill -f tmux
.Hope it helps.
I can kill all of these processes with the command:
It kills all processes (full list) of the matching name (tmux).
Note for newcomers: This way could serve you to kill all process of other matching names.
This would list and kill all the sessions:
Given:
This will kill all sessions not attached by someone:
References:
I have written a small app in C which does this.
It's called kkill, you can simply
this will kill all tmux processes running. it is a lot simpler than pkill.
https://github.com/giorgossaridakis/kkill
21 December 2021 - updated kkill.c, added a tsr kkiller.c who 'll watch for processes and send them SIGKILL as they become active
Here another solution that allows you to select easily between useful sessions and the ones to delete, enter in
tmux
:Check your sessions pressing:
Then move with the arrows and press
t
to target as many sessions as you want to kill.Press
:
and writeI think this solution is the faster one as you don't need to write the name or number of the sessions to delete, but you rather use the UI of the own tmux to delete all selected at the same time.
In the same menu, you can also delete them one by one pressing
x
to delete andy
to accept the deletion, so you write even less if you don't have many sessions to delete.Kill all sessions with no one attached (based on this answer):