如何删除分离的tmux会话?


25

我脱离了tmux会议:

$ tmux ls
0: 1 windows (created Thu Aug 22 22:52:17 2013) [218x59]

无论如何,既然我已经与它分离了,我现在可以简单地将其删除吗?


相关:如果您仍连接到tmux会话,则可以按Cd(控件+ D)使其脱离并一举删除。(假设您在shell提示下。)
stalepretzel 2014年

Answers:


41

您要使用tmux kill-session

<~> $ tmux ls
0: 1 windows (created Sat Aug 17 00:03:56 2013) [80x23]
2: 1 windows (created Sat Aug 24 16:47:58 2013) [120x34]

<~> $ tmux kill-session -t 2

<~> $ tmux ls
0: 1 windows (created Sat Aug 17 00:03:56 2013) [80x23]

2

如果要删除所有分离的会话,可以使用以下代码:

tmux list-sessions | grep -E -v '\(attached\)$' | while IFS='\n' read line; do
    tmux kill-session -t "${line%%:*}"
done

此解决方案比abieler提出的解决方案更健壮,因为它grep -E -v '\(attached\)$'仅匹配分离的会话(abieler的解决方案将跳过称为attached的分离的会话)。


0

如果您想杀死所有独立的会话

tmux list-sessions | grep -v attached | cut -d: -f1 |  xargs -t -n1 tmux kill-session -t

带有注释/解释:

tmux list-sessions   | # list all tmux sessions
  grep -v attached   | # grep for all lines that do NOT contain the pattern "attached"
  cut -d: -f1        | # cut with the separator ":" and select field 1 (the session name)
  xargs -t -n1       ` # -t echoes the command, -n1 limits xargs to 1 argument ` \
  tmux kill-session -t # kill session with target -t passed from xargs

1
您可以在这里对您的实际工作进行一些描述吗?另外,这会杀死所有附加的会话,您应该注意这一点。
djsmiley2k-CoW

@ djsmiley2k您表示的所有独立会话(-v标志)。
巴特·卢维尔
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.