116

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) ?

| improve this question | | | | |
209

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 use tmux kill-session -t targetSession to kill that specific session.

Also you can grossly kill all tmux processes with pkill -f tmux.

Hope it helps.

| improve this answer | | | | |
  • 1
    ps aux | grep tmux after tmux kill-server still shows a tmux process... Same goes with pkill -f tmux as in my answer. Can you explain this? Thanks, – user423047 Jan 5 '17 at 6:20
  • 1
    @Benia are you sure you are not just seeing the grep tmux process (which is included in the ps output of your original question)? – steeldriver Jan 5 '17 at 13:45
  • 2
    If you issue ps aux | grep blablablawhichdoesntexist it will always show at least one line, corresponding to the grep blablablawhichdoesntexist command. – dgonzalez Jan 5 '17 at 14:14
  • 1
    Are you missing -t flag, cos it shows error without -t flag set for killing a particular session. Usage: kill-session [-a] [-t target-session] – 1rq3fea324wre Nov 1 '17 at 3:03
  • 1
    It used to be very painful tmux ls | grep : | cut -d. -f1 | awk '{print substr($1, 0, length($1)-1)}' | xargs kill – Foad Feb 1 '18 at 14:35
22

I can kill all of these processes with the command:

pkill -f tmux

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.

| improve this answer | | | | |
17

This would list and kill all the sessions:

tmux list-sessions | awk 'BEGIN{FS=":"}{print $1}' | xargs -n 1 tmux kill-session -t
| improve this answer | | | | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy