I accidentally opened 32 "Archive Manager" tabs. How can I close them all instantly, as if using Alt+F4 on all of them at once.
3 Answers
From command line:
killall file-roller
You can do alt+f4 but you need to do that for every archive manager that was opened.
- 293,910
- 41
- 570
- 710
-
21Though some might argue that the "killall" command is a bit heavy-handed, yours is still a much more humane solution than the `kill cat` action I was going to suggest. – Nick Weinberg Apr 23 '17 at 18:20
-
I don't think there is an easier way to stop them all. Lots of alt+f4's would do it to but that was not the question ;-) – Rinzwind Apr 23 '17 at 18:34
-
file-roller i suppose it is the process, so i just can check `gnome-system-monitor` and seek for the process and write down `killall process` and it's gone. And for @Rinzwind, I can do that too, but I wanted to know if there is a way possible to kill them all – sticsk Apr 23 '17 at 18:55
-
No "killall {programname}", "killall process" would just kill 1 of them. And you can also kill it from system-monitor, no need to go to command line if you want to kill just one process. – Rinzwind Apr 23 '17 at 20:24
-
5@NickWeinberg I appreciate it :) – cat Apr 23 '17 at 22:15
-
But `killall` *is* humane, the default signal equals to asking to terminate just like closing a window or tab would do. – mike3996 Apr 24 '17 at 07:22
-
5I read this question and answer wrong. I thought it was about the cat had closed all, and that OP didn't know how the cat did it. I was amazed that the cat was able to write `killall file-roller` :D – Viktor Mellgren Apr 24 '17 at 07:31
-
1damn @ViktorMellgren stop making me spil coffee on my screen – Rinzwind Apr 24 '17 at 09:20
Another approach would be to use the wmctrl utility (Window Manager control). This can be used to tell the window manager to pretend you clicked the close button. This avoids the potentially heavy-handed nature of killall; for example, some programs with an unsaved document will immediately exit when they are killed (even gently), while clicking the close button brings up a "Do you wish to save?" prompt.
The basic command is wmctrl -c WINDOWTITLE, so in this case wmctrl -c "Archive Manager" (assuming it has no open file: that changes the title). Unfortunately, it only closes one at a time, so we need to do more to close all of them.
wmctrl returns success if it finds a match, so we can loop until it fails:
while wmctrl -c "Archive Manager"; do sleep 0.1; done
This always chooses the first window it finds, so we need to sleep for a bit to avoid continuously sending a stream of close commands to the first window that's already busy closing - that can cause an error which stops the loop.
This is simple and usually works, but sleeping a set amount of time and hoping a window closes before we try again is a messy and slow way to avoid the error. What we really want to do is to immediately send one close message to every matching window.
We can find all open windows with wmctrl -l. This lists a numeric window id that we can use to identify each window individually, even if they all have the same title. Then we need to filter to only the matching windows (the grep command), pull out just the window id (the cut command) and call wmctrl -i -c for each one. The -i is needed to match the window id instead of the window title.
for w in $(wmctrl -l | grep "Archive Manager" | cut -d" " -f1); do
wmctrl -i -c $w
done
A bit complicated for just typing in whenever a cat steps on your keyboard, but hopefully a handy technique to keep in your scripting toolbox.
- 141
- 2
You can use the Ctrl+Q keyboard shortcut which will close all opened windows of Archive Manager.
The Ctrl+Q shortcut is common on Ubuntu (and lots of other distributions as well). It works the same with most of the applications I've used thus far. That is, it will close all windows of a running application.
- 12,494
- 7
- 70
- 94
-
Undone my vote, since I can't confirm that `Ctrl+Q` actually does that. While the `Quit` menu did close all opened windows of Archive Manager, the shortcut key did not do the same (at least in 14.04). – Apr 24 '17 at 12:52
-
1@clearkimura I cannot confirm if it's due to the fact that I'm using gnome, or if it's because of the Ubuntu version, but it works for me on Ubuntu 17.04 (with gnome) which uses Archive Manager version 3.22.3 – Dan Apr 24 '17 at 13:16