Guide

How to Close All Apps at Once on Linux

Linux has no “close everything” button, and the advice you find first is usually killall — which is the one command here most likely to log you out. The distinction that matters is between applications (things with a window) and the session (your shell, compositor, D-Bus, systemd user services). Closing the first set is what you want. Killing anything in the second drops you back to a login screen with everything unsaved gone.

Below: the tools that target windows rather than process names, the ones to avoid, and a one-click option.

Method 1: wmctrl (the right tool for X11)

wmctrl talks to the window manager rather than to the process table, so it only ever sees things that have a window. That is exactly the set you want to close. Install it with sudo apt install wmctrl(or your distro’s equivalent), then list what is open:

wmctrl -l

Each line is one window. To close them all, politely, in the same way clicking the window’s X does:

wmctrl -l | cut -d' ' -f1 | xargs -n1 wmctrl -i -c

The -c flag sends _NET_CLOSE_WINDOW— a request, not a kill. Applications get to run their shutdown code, flush files and exit cleanly, which is why you will not see “restore your session?” prompts the next time you open them.

The catch: a request can be declined. An app showing an unsaved-changes dialog will sit there waiting for an answer, so wmctrl alone does not guarantee an empty desktop.

Method 2: xdotool

xdotool covers similar ground with more precision, and is handy if you want to close windows matching a pattern rather than all of them:

xdotool search --name ".*" windowclose %@

Use windowclose (graceful) rather than windowkill (abrupt) unless you have a reason not to. Both wmctrl and xdotool are X11 tools — see the Wayland note below.

Method 3: pkill, carefully

If you want to close a specific application and know its process name, pkill is fine:

pkill -TERM firefox

SIGTERM is the polite signal — the process can catch it and shut down properly. Reach for SIGKILL (pkill -9) only when something has genuinely stopped responding: it cannot be caught, so the application gets no chance to save anything or clean up temporary files.

Not the fix: killallwith a broad pattern, or any variant of “kill everything owned by my user”. Your user owns the session too. pkill -u $USER will cheerfully terminate systemd --user, your compositor and your shell, and the visible result is being logged out mid-sentence.

Method 4: one click from the tray

Captain Kill Switch does the same thing the safe commands above do, with the gap closed. Every window gets _NET_CLOSE_WINDOW first — the same polite request wmctrl -c sends — and anything still running about two seconds later gets SIGTERM, so an app sitting on a save dialog does not stall the whole sweep. An allowlist model means only ordinary applications are ever targets: the shell, session infrastructure and the operating system are never touched, so it cannot log you out.

It is a tray app, not a script: a webkit-free 3.4MB static binary with no Electron and no webview, from a signed apt repository so updates arrive with your normal system updates. There is also a cks command-line version with a --dry-run flag, which prints exactly what a sweep would close without closing anything — worth running once before you trust it.

The honest trade-off: two seconds is not long enough to answer a save dialog, so unsaved work closes. Save first. What you get in exchange is a genuinely clean desktop in seconds, with your session intact.

A note on Wayland

On Wayland there is no global window list — by design. A client cannot enumerate or close another client’s windows, which is a security property of the protocol rather than a missing feature, and it is why wmctrl and xdotool do nothing useful in a Wayland session.

Applications running through XWayland still respond to the X11 tools above. Native Wayland windows can only be asked to exit via their process, so SIGTERM is the ceiling there. Anything claiming to close all Wayland windows from outside is either using a compositor-specific protocol or signalling processes and calling it something else.

Quick comparison

  • wmctrl — polite, window-aware, X11 only. Can be declined by a save dialog.
  • xdotool — same idea, finer targeting, X11 only.
  • pkill -TERM — good per application; dangerous with broad patterns.
  • killall / pkill -u — avoid. Targets your session as readily as your apps.
  • Captain Kill Switch — one click, polite first with a force floor, session-safe, free.