How do I kill all screens?

I accidentally created over 1000 screens. How do I kill them all with one command? (Or a few)

Asked By: BrainStone


You can use :

pkill screen


killall screen

In OSX the process is called SCREEN in all caps. So, use:

pkill SCREEN


killall SCREEN
Answered By: Rahul Patil

I’m a bit puzzled over how you managed to create 1000 “screens”. Did you perhaps mean 1000 screen windows (1000 different terminal windows within a single screen session)?

If you meant 1000 windows within a single screen session, then a more elegant solution would be to quit screen using the command C-a (ctrl-a followed by ).

Answered By: Railgun2

If the screens are dead, use:

screen -wipe
Answered By: Adam_G
str=$(screen -ls)  

array=$(echo $str|tr "." "n")  

for V in $array  
if [ $V -gt 0  ]  
        then screen -S $V -X quit  
Answered By: Don Wei

Have recently begun to familiarize myself with awk I put together this and it served its purpose. I posted it since its quite easy to understand.

screen -ls | grep '(Detached)' | awk 'sys {screen -S $1 -X quit}'

Where screen -ls lists all current screens.
grep 'pattern' filters out all matching rows. We can then get a handle for all detached screens and with awk sys {command} we can copy and paste together a command and execute it with sys, $1 refers to the first argument picked up by awk. Finally we execute the quit command with screen -X quit.

Answered By: Eliassen

The following command will terminate all inactive screens:

perl -e 'while (map { kill 9, [split /./]->[0] } grep { /Detached/ } split /n/, qx{screen -ls}) { sleep 1 } exec qw(screen -wipe)'
Answered By: Michael Vu
for scr in $(screen -ls | awk '{print $1}'); do screen -S $scr -X kill; done
Answered By: user370823

You can use the screen command itself to list all active screen sessions and then kill them one by one. Here’s an example:

screen -ls | awk '{print $1}' | xargs -I{} screen -X -S {} quit

This will list all active screen sessions using the screen -ls command, extract the session IDs using awk, and then pass each session ID to the screen -X -S command to quit the session.

Answered By: Mahesh Belnekar

pkill screen

to list all screens, use screen -ls

Answered By: Kiler_630
Categories: Answers Tags: , , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.