![终止所有同名的屏幕会话](https://linux22.com/image/1497098/%E7%BB%88%E6%AD%A2%E6%89%80%E6%9C%89%E5%90%8C%E5%90%8D%E7%9A%84%E5%B1%8F%E5%B9%95%E4%BC%9A%E8%AF%9D.png)
由于错误,我有多个同名的屏幕会话。如何在不影响其他屏幕会话的情况下,用一个命令删除所有这些会话?
我使用了这篇文章中的命令: https://stackoverflow.com/questions/1509677/kill-detached-screen-session
但是它只打印出会话并且不会删除它们:
我该怎么做才能一次性删除这些会话而不影响其他会话?
谢谢
答案1
这是我用来关闭所有名为 my_screens_to_kill_named_the_same 的屏幕的方法:
# Checking if there are some screen named
if screen -list | grep -q "my_screens_to_kill_named_the_same"; then
# Get the list of id of screens named
ids_to_kill="$(screen -ls | awk '/\.my_screens_to_kill_named_the_same\t/' | awk '{print strtonum($1)}')"
# Loop on that list and kill all the screens named
for id_to_kill in ${ids_to_kill}
do
screen -X -S "$id_to_kill" quit
done
fi