I'd like to know or it is possible to set up the GNOME Terminal in a way that when I open up the terminal and there is already an instance open it'll show that instance and not open up a brand new one.

  • what version of ubuntu are you using, and which environment? I ask, because what you are describing is the default setup in unity and gnome-shell.
    – martin
    Nov 24, 2011 at 12:57
  • I’m using Ubuntu 11.10 with Unity-2D. I haven’t done a clean install but an upgrade from 11.04.
    – Mood
    Nov 25, 2011 at 0:46
  • Do you use Ctrl+Alt+T as a shortcut?
    – int_ua
    Dec 9, 2011 at 12:54
  • Yes I do.That or I start up a terminal typing “ter » enter” in Kupfer. Those are the the 2 methods I use. Because I don't look on the Unity laucher all too often I end up with 3, 4 different terminals.
    – Mood
    Dec 10, 2011 at 17:18

5 Answers 5


I wrote a simple shell script using wmctrl to give the Terminal focus. It does exactly what I want.

First, install wmctrl sudo apt-get install wmctrl.

Next, fire up a text-editor, copy the following lines.


if ps ax | grep -v grep | grep $SERVICE > /dev/null
  wmctrl -xa $SERVICE

Save the file somewhere where you usually keep your shell scripts. In my case I did: ~/bin/single_instance.sh

cd to the directory (cd ~/bin) and make the file executable chmod +x single_instance.sh

Now, open up Main Menu select Accessories » Terminal press properties and replace command with the script: ~/bin/single_instance.sh

Open up System Settings » Keyboard » Shortcuts. Disable Launch Terminal shortcut by giving it a backspace. Make a custom shortcut. Again fill in the path and name to the script and give it the key combination ctrl + alt + t.

You’re done, single instance terminal...

  • Why not just make your script the default terminal launcher? Why all the steps to add shortcuts and all? +1 for the script, -1 for the implementation. Dec 12, 2011 at 16:18
  • In all honestly… I don't know how to do that. I’ve looked at default applications and didn't see terminal. Also I'm convinced that the previous version of Ubuntu had text-fields where commands could be entered. This version of default apps is all drop down menus.
    – Mood
    Dec 12, 2011 at 19:21
  • anyway to get this working with wayland?
    – Brad
    Apr 28 at 6:07

Add --tab to the launcher command. Then you end up with only one app. open.

~$ gnome-terminal --help-all
--tab       Open a new tab in the last-opened window with the default profile
  • No, I don't want a new tab. I want the terminal to move to the foreground in the state I last left it.
    – Mood
    Dec 12, 2011 at 11:28
  • 1
    This just opens new windows for me on Ubuntu 16.04
    – beruic
    Jul 26, 2016 at 8:45

It is the default behavior if you use Mod4+# (Mod4 = Super = "Windows" key, # is number in launcher) shortcut to open any application.

  • Yes I’m aware of that. Still, I have to have a terminal open to begin with. I meant when I press control + alt + t or open it up in Kupfer. I’m looking for the same behavior as – for example – Chrome: If an instance is open show me that instance, if there no instance open a new instance.
    – Mood
    Dec 10, 2011 at 13:04

I generalized and simplfied @Mood 's script a bit. Now it takes a command line parameter and use pgrep instead.

sudo apt-get install procps

The script:

#!/usr/bin/env bash

if pgrep $1
    wmctrl -xa $1

I'd like to add my own script, since I find it extremely useful:

  1. If there is a gnome-terminal in the current workspace, then it brings it to the front and gives it focus
  2. If there isn't any gnome-terminal in the current workspace, it switches the workspace and brings the first existing gnome-terminal it finds to front and gives it focus
  3. If there are no gnome-terminal instances running, it opens a new instance, brings it to front and gives it focus

I configured Ctrl+Alt+T shortcut to run this script and I find it even more comfortable than Guake or Tilda.

#!/usr/bin/env sh

# APP is the binary name you see when you do ps
# WIN_CLASS is the window class you see when you do wmctrl -lx

# Use the app from current workpace first, or any if not available
WORKSPACE=$(wmctrl -d | grep '\*' | cut -d ' ' -f1)
TPID=$(ps aux | pgrep $APP)
if [ "$TPID" ]
  QTERM_WIN=$(wmctrl -lx | grep $WIN_CLASS | grep $WORKSPACE  | awk 'NR == 1 {print $1}')
  if [ "$QTERM_WIN" ]
    wmctrl -ia $QTERM_WIN
    # No valid app found in the current workspace, switch to any
    QTERM_WIN=$(wmctrl -lx | grep $WIN_CLASS | awk 'NR == 1 {print $1}')
    wmctrl -ia $QTERM_WIN
  $APP &

I use it with QTerminal but I modified to fit your needs. Good luck

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.