Tuxtips - Linux HowTos

Linux HowTos live here

How to close all open windows in Linux

21 Aug 2020

One of the most annoying things in any operating system is a situation when you have many open windows and you suddenly want to power off your computer and rush to do something urgent. To avoid future problems you should gracefully close all the windows one by one. There is a way to do it with a key combination, but first you need to set it up.

First, you need to install wmctrl, then open your preferred text editor and create the following script:

for n in $(wmctrl -l | awk $2 '!/-1/ {print $1}')
    wmctrl -i -c $n;

Save the file, for example as close.sh somewhere within your home directory. Then open your terminal, cd into the directory your script is located and make it executable:

click code to copy
chmod +x close.sh

Now you need to create a keyboard shortcut that runs the script. For example in XFCE you should open the settings configuration, find the Keyboard section, switch to Application Shortcuts and add the shortcut command, which is the location of your script, e.g. ~/scripts/close.sh. Finally, you will be prompted to set the key combination to run the command. I use Super + Shift + Escape.

From now on, whenever you want to close all your open windows you just use your keyboard shortcut.
Tested on: Arch Linux and Linux Mint 20 XFCE, August 2020.
Comments Add your comment

Enter the digit "three" (spam protection):

powbam1 year ago
So nice. Thanks for this - got it working in short order in Manjaro KDE with no issue. I did notice that for Steam it completely kills the app instead of just closing the window while an app like Discord will close the Window but continue living on down in the taskbar.

Not a huge deal but it seems to be a thing.

Enter the digit "three" (spam protection):