Kill all detached screen sessions

前端 未结 6 1821
时光取名叫无心
时光取名叫无心 2021-01-29 20:47

When I execute screen -ls, I see the following. How can I kill all the detached sessions?

There are screens on:

    84918.tty         


        
6条回答
  •  时光取名叫无心
    2021-01-29 21:34

    Here's a solution that combines all the answers: Add this to your .bashrc or .bash_profile:

    killscreens () {
        screen -ls | grep Detached | cut -d. -f1 | awk '{print $1}' | xargs kill
    }
    
    • this is a convenient function, easy to remember
    • kills only the detached screens, to stop you from doing something dumb
    • remember to open a new bash terminal or run source .bashrc to make killscreens available

    Thanks to @Rose Perrone, @Milind Shah, and @schatten

提交回复
热议问题