Does a shell command exist to bring a already started program in gnome in the front of another.


Gedit and Nautilus are started. Nautilus is in the background and Gedit in the foreground.

How to i bring Nautilus in the front with a shell command?


3 Answers 3



  • More information about xdotool can be found here.
  • Sure edit your post just as I'm composing mine... :( )
    – frabjous
    Jan 12, 2011 at 20:58
  • You can find your window name with wmctrl -l The name is the text after the last dash: <window ID> <desktop ID> <client machine> <window title>
    – jorfus
    Jul 13, 2018 at 22:03

Another option is xdotool:

xdotool search --class Nautilus windowactivate

  • 4
    Fails for me with XGetWindowProperty[_NET_WM_DESKTOP] failed (code=1)
    – Tino
    Oct 11, 2016 at 19:11
  • Probably the bug here -- in my experience --classname or --name (if known) works sometimes when --class doesn't.
    – frabjous
    Oct 20, 2016 at 19:04
  • In my case it was possible to raise a window using the ID from xwininfo and issuing several additional different xdotool commands (which I no more remember). When I tried to automate that (to get rid of xwininfo) I got visual artifacts due to otherwise hidden windows which were selected, too. I simply found no generic way to address arbitrary windows correctly. After switching to wmctrl -a everything immediately worked flawlessly out of the box without any further tweaking. Please note that I like xdotool, but it seems to be difficult to raise just the correct window with it.
    – Tino
    Oct 27, 2016 at 10:29
  • 1
    xdotool search --desktop 0 Nautilus windowactivate did it for me
    – Allanrbo
    May 19, 2020 at 7:05

When using xdotool, it seems difficult to bring to front all windows for a given application or class using only one command. I end up having better results by wrapping it in a for loop at the shell level. Using Bash:

for WINDOW in $(xdotool search --desktop 0 Firefox); do
   xdotool windowactivate ${WINDOW}

Few remarks:

  • By default, xdotool search will search the pattern (here Firefox) in window name, class, and classname. If you want to restrict your search space, use the relevant --class, --name or --classname options.
  • The --desktop 0 option limits the search to the first desktop. This seems to be a workaround to avoid the XGetWindowProperty[_NET_WM_DESKTOP] failed (code=1) mentioned in some comments.
  • At the time of this writing, the xdotool project is stalled since 2015. It still remains my tool of choice though. For personal reasons, Jordan Sissel (the original author) is not as active as he was, so don't hesitate to contribute to the project.
  • 2
    If you want to bring up all the windows of an application, instead of a for loop you can use %@ which applies it to all windows. Also, you'll want --onlyvisible option to avoid fake or invisible windows. For example, xdotool search --onlyvisible --class firefox windowactivate %@ will bring up every firefox window. If you omit %@, you'll only get the first one. You can choose which one you want by changing @ to a positive integer such as %2. Make sure you remember the --onlyvisible, especially if you don't use %@ or you probably won't get any windows.
    – Haggra
    Nov 5, 2020 at 3:10

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.