This is half "this'd be useful for me" and half "hobby project" - I was wondering if it's possible to send a command via a gnome-terminal that will quit all instances of a program without using killall.

Essentially I'd like to write a script, which I will put in my $PATH, that will try and exit all open terminal windows as if the close button had been clicked on each, rather than killing. The reason being that I have a terrible habit of opening many terminal windows at once and it's a hassle to go through each of them and quit all of them individually. Simply typing exeunt (because let's face it, there's no better name for a command to "exit all") and having them all quit would be far better for me. However, I don't want to accidentally close any programs that are still running from within a terminal - I still want to see any "There is still a process running in this terminal" prompts, so the command killall gnome-terminal would be out of the question.

The ideal I suppose would be a command-line / bash equivalent of rightclicking on the Dash icon and pressing "quit". Possibly a slightly unorthodox request, but I'd be interested to know if it's somehow possible.


Despite it's name, killall (and kill) sends SIGTERM signal to all the process with the same name, also you can personalize the signal sent with the -s switch. So, instead using killall gnome-terminal you can use killall -s {signal} gnome-terminal.

I haven't find out what signal can be interpreted as click at the close button, but my guess is, that it's a GUI hook that trigger such behavior. In gnome2 there was a "Close all" option in the task list, but in gnome3 seems such option it's lost.

After a lengthy discussion over U&L

With the help of slm who gave me the idea, you can simulate the alt + F4 key combination on several instances of gnome-terminal using xdotool search --name terminal key --window %@ alt+F4. You must be sure you have installed xdotool using:

sudo apt-get install xdotool

But, lets me explain in detail:

search do a search of all window with a determinated characteristics. --name switch will look for windows with the content on the title bar. key tells xdotool that we are going to use keyboard commands. --window tells to use a determinated ID for the key command, if not set it will use %1 from the stack. %@ means to use all the stack of ID's. alt+F4 tells the key combination to send.

More information:


| improve this answer | |
  • 1
    killall (and kill) only send an actual KILL signal when you explicitly tell it to do so, the default signal is TERM(inate). You can look up all the signals in man 7 signal. – Gerald Schneider Aug 1 '13 at 12:16
  • Interesting. Is there a signal that I can send that'd be interpreted as an alt-f4 or a "close", though? Otherwise the only way I can think of along these lines would be to delve into the gnome terminal source and put in a handler for SIGUSR1 / 2 to tell it to close cleanly, by the looks of that list. – Jez W Aug 1 '13 at 13:00
  • Sorry, been away for a while. Seems like a very nice solution, but doesn't quite seem to work as expected (by the look of things it sends an alt-f4 signal for each open terminal window, but doesn't switch between them in between - so what happens is the "Close this window?" prompt flashes on and off for a little bit for the terminal window in which the command is run (as xdotool counts as a running program while the command is still running) – Jez W Aug 21 '13 at 16:05
  • @JezW Well, you actually asked how to "Quit all instances of gnome-terminal via a command" which this answer do at the perfection. If you want to do something more elaborate, ask another question or read the manual ;). – Braiam Aug 21 '13 at 16:12
  • It doesn't, though. When I type it, it brings up a "close this window?" prompt for the active terminal window (and even then only if there are an odd number of terminals open - if it's an even number the prompt flickers on and off and disappears) - it doesn't have any effect on any of the other open windows... – Jez W Aug 22 '13 at 11:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.