Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

After I navigate out to a webpage or editor, is there any way to bring all the open terminals back to the front in their original positions? It is a bit of a pain clicking the terminal icon and then bringing each one back individually.



  • Pre-shortcut:

Pre-image shortcut

  • Post-shortcut:

Post-image shortcut

share|improve this question
+1 very interesting question, you might find this answer to an unrelated question useful -- the devilspie program could be relevant to this problem if there isn't an existing GUI tool. – evilsoup Sep 16 '13 at 9:08
up vote 4 down vote accepted

You can press Alt+Tab to switch forward between windows and Alt+Shift+Tab to switch back between windows. This shortcut is made to work in almost all graphical operating systems. Yow can also use Super+W and arrow keys for the same purpose.

After you bring one terminal window in the front, press Alt+~ to bring all other terminal windows in the front one by one:

switch to windows

To automatically bring all open terminals in the front (not one by one as I described before) you will need to add a keyboard shortcut for the following script (script taken from Adobe's answer and improved considering that version of script hasn't worked for me):


if [ $# -ne 1 ];then
  echo -e "Usage: `basename $0` PROGRAM_NAME\n
           For example:\n\t
           '`basename $0` gnome-terminal' for Terminal\n\t
           '`basename $0` firefox' for Firefox\n\t
           '`basename $0` chromium-browser' for Chromium\n\t..."
  exit 1

pids=" $(pidof $@) "

if [ "$pids" = "  " ]; then # the string "  " contain two spaces
    echo "There is no program named '$@' opened at the moment."
    exit 1

wmctrl -lp | while read identity desktop_number PID window_title; do 
    if [ "${pids/ $PID }" != "$pids" ]; then
        wmctrl -ia $identity

Don't forget to make the script executable:

chmod +x /path/to/script/script_name

After you test the script in terminal, you must to see:

share|improve this answer
Thanks but that is essentially the same as clicking the terminal icon and selecting each one to bring to the front. I mean a short cut which will bring all open terminals to the front. An example being I could be writing code in gedit, want to compile it in one terminal while watching the output of a log in another terminal. – Tom celic Sep 16 '13 at 8:42
"Screenshot will be taken in 1 second"... hmm someone just lied here... – Carlos Campderrós Sep 16 '13 at 11:34
@Tomcelic See my new edits. Want to say that I was working on such a script while Adobe has posted his How to Answer(which for me hasn't worked), so please do not take this in the wrong way. – Radu Rădeanu Sep 16 '13 at 12:27
Works perfect thanks! – Tom celic Sep 16 '13 at 12:35

Here's a small bash script which brings all the windows whose title matches ARG to the front:

bring-all-windows.bash ARG

The script:



wmctrl -l | while read Window; do
    if [[ "$Window" == *"$Program"* ]]; then
        echo "DEBUG: I bring $Window"
        code=`echo "$Window" | cut -f 1 -d " "`
        wmctrl -i -a $code

You can bind

bring-all-windows.bash Terminal

to a hotkey (don't forget to put the script in a login shell PATH, or write a full path to it).

The script requires wmctrl to be installed.


To run something from the terminal, navigate to the dir where you put the script, then

chmod +x bring-all-windows.bash
./bring-all-windows.bash Terminal

When you're sure it works from the terminal, try to bind it to a hotkey, giving the full path. When you're sure it works with a hotkey and the full path to the script, then try adding it's dir to the login shell PATH, and see if it works that way.

share|improve this answer
This sounds good! I will give it a try shortly and get back to you. I'm still a bit stumped as to why there isn't a native method for this, it seems like it should be natural. – Tom celic Sep 16 '13 at 9:36
@Tomcelic: There's a wmctrl and bash: that's natural. – Adobe Sep 16 '13 at 9:37
True but it's not native :P – Tom celic Sep 16 '13 at 9:41
Is there any chance you would mind running through how to use this script?? I have created the script and saved it in my home folder and added it's path to /etc/shells. I have also added a shortcut in keyboard settings with the name bring_terminals_forward and the command is bash /home/michael/Scripts/bring-all-windows.bash Terminal – Tom celic Sep 16 '13 at 10:45
Running the script directly from a running terminal doesn't seem to work either... It works for programs like gedit, but not for Terminal – Tom celic Sep 16 '13 at 10:47

Another way is using xdotool. You should install it first so sudo apt-get install xdotool is mandatory.

xdotool search --class "terminal" windowactivate %@
xdotool search --name "braiam@bt" windowactivate %@

The first look for any binary called *terminal*, the second looks for any window that has as title *braiam@bt*. Then if you put that into a bash script:


set -e

xdotool search --class '$program' windowactivate %@
xdotool search --name '$program' windowactivate %@

You can know more about this in the xdotool manual.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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