I am running Ubuntu GNOME 15.10 with GNOME 3.18 and I am wondering if there is a way from Terminal to close, minimize, unminimize, maximize, and unmaximize specified windows?

Note - I've looked at this Q&A - I am asking how to do it from Terminal... Not how to add the buttons... The buttons are already there, I don't need to add them.

  • 2
    Possible duplicate of Can I minimize a window from the command line?
    – Anastasia
    Nov 28, 2015 at 18:48
  • @Anastasia: How is this a duplicate of that? That only asks about minimizing... I'm asking about all of the other stuff as well which is not answered there.
    – user364819
    Nov 28, 2015 at 18:51
  • I assumed those actions are so closely related that answering one should lead to all the others, but you're right, that may be a broad sweep. Now I'm also wondering in subsets of questions can be considered duplicates.
    – Anastasia
    Nov 28, 2015 at 19:03
  • @Anastasia: Well, because the answers to the other question don't actually mention how to achieve this, even if they would help me, it is still not a duplicate of that question. Plus even if the answers to the other question answer my question, my question still isn't asking the same thing as the other one is asking.
    – user364819
    Nov 28, 2015 at 19:07
  • Hi Para, I hope the question is still "open". An overview... Feb 29, 2016 at 20:30

3 Answers 3


There are two important tools to manipulate windows from cli; xdotool and wmctrl. Both tools overlap each other in functionality, but the most important commands referring to your question:

In an (no doubt incomplete) overview, listing the commands I use most:

Closing a window


wmctrl -ic <window_id>

Minimizing a window


xdotool windowminimize <window_id>

Un- minimizing a window


effectively un- minimizing is done by:

wmctrl -ia <window_id>

I mention effectively, since the command moves to the corresponding desktop, unminimizes and raises the window, but the command also does that on windows which are not minimized.

Maximizing a window


xdotool windowsize <window_id> 100% 100%


wmctrl -ir <window_id> -b add,maximized_vert,maximized_horz

Un- maximizing a window:

wmctrl -ir <window_id> -b remove,maximized_vert,maximized_horz


  • Both xdotool and wmctrl are not on your system by default:

    sudo apt-get install xdotool wmctrl
  • To run any of the commands on the currently active window:

    • for wmctrl commands, remove the -i option, replace <window_id> by :ACTIVE:

    • for xdotool commands: replace <window_id> by $(xdotool getactivewindow)

  • In many cases, commands can be run by using either the window id or the window name. The -i option in wmctrl tells wmctrl to use the window id. I'd suggest not using the window's name as an identifier, to prevent name clashes. It happens more easily then you'd expect.

  • From my own experience, using maximizing in a script; Using wmctrl to maximize / unmaximize can be a bit buggy on both Unity and Gnome, while the xdotool option works more robust in my experience. In most scripts, I end up in using a mix of both wmctrl and xdotool.

More info on man wmctrl and man xdotool (mainly the section: WINDOW COMMANDS).

  • 1
    Thanks for the great answer! But how do you also unminimize a window?
    – user364819
    Feb 29, 2016 at 21:22
  • 1
    @ParanoidPanda see my updated answer :) Mar 3, 2016 at 13:42
  • 1
    wmctrl -ir <window_id> -b remove,maximized_vert,maximized_horz not work on gnome 3.20
    – user41209
    Apr 9, 2019 at 14:38
  • The xdotool minimize command didn't work for me. I found the command "xdotool getactivewindow windowminimize" worked though. I found that command here
    – akovia
    Jun 5, 2020 at 12:04
  • Completely failed to specify how to even get window id
    – Andrew
    Aug 1 at 17:01

Adding to Jacob Vlijm's answer:

xdotool windowactivate $minwinid
xdotool windowraise $minwinid
xdotool windowfocus $minwinid

Also works for unminimizing a window. The animation is faster for me.


Adding to Jacob Vlijm's answer:

Minimizing a window w/ xdotool by window name:

xdotool search -name '<window_name>' windowminimize

To get list of windows names use:

wmctrl -l

Your Answer

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