69

I installed xdotool by running sudo apt-get install xdotool and throw xdotool key ctrl+alt+t command to open a new terminal window from the current one.But it was not working.

What was the command to open a new terminal window from the current gnome-terminal?

1
  • 2
    ctrl + shift + n
    – wim
    Jan 6, 2014 at 17:57

3 Answers 3

101

Just this command will do:

gnome-terminal

Normally if you want a command to open from the terminal and separate (so it returns to the prompt without having to close the opened program), you have to use something like this:

gnome-terminal & disown

However the parent terminal seems to detect that the same command is being used so you don't need to do that and gnome-terminal will suffice. This also seems to happen when running xfce4-terminal from Xfce's terminal, konsole from KDE's as well (doesn't seem to work when running xterm from xterm (see also xterm xterm) - Running konsole from Gnome/Unity & Xfce's terminal works as well, but for Xfce's terminal in gnome terminal you need xfce4-terminal & disown).

For more visit gnome-terminal's manual page:

 gnome-terminal  [-e,  --command=STRING]   [-x, --execute ]  [--window-with-profile=PROFILENAME]  [--tab-with-profile=PRO‐
       FILENAME]    [--window-with-profile-internal-id=PROFILEID]    [--tab-with-profile-internal-id=PROFILEID]    [--role=ROLE]
       [--show-menubar]   [--hide-menubar]   [--geometry=GEOMETRY]   [--disable-factory]  [-t, --title=TITLE]  [--working-direc‐
       tory=DIRNAME]  [--usage]  [-?, --help]
9
  • 2
    You probably want to run it in the background, like that: gnome-terminal &. Otherwise the current terminal will be unusable, as it will be busy running that other one - so you end up with just one usable terminal, which may be missing the point. Jan 6, 2014 at 19:59
  • 1
    Interesting. You are apparently right, however, I am not wrong neither :) I've just checked that in details. If I run gnome-terminal while another instance of it is already running (it may be the one I'm using to launch this command) - it indeed finishes immediately, because instead of running a new instance gnome-terminal, it tells that currently running one to open a new window. Tricky. But if I run gnome-terminal from anything else, and there are no other instances of gnome-terminal running, it does as I explained in the previous comment, blocking the terminal used to launch it. Jan 6, 2014 at 20:25
  • 1
    @RafałCieślak - anyway, konsole doesn't seem to need at all... weird. I have no idea why this question/answer is so popular :)
    – Wilf
    Apr 22, 2015 at 14:34
  • 2
    Thanks very much, if you want to open a terminal with the same directory you could do this, gnome-terminal . Jul 7, 2015 at 4:58
  • 1
    If you are on Ubuntu MATE (e.g. 16.x) it's mate-terminal
    – Frank N
    Oct 27, 2016 at 1:54
11

Command to open new terminal window from the current terminal,

xdotool key ctrl+shift+n

To install xdotool,

sudo apt-get install xdotool
6
  • 4
    Ctrl+Shift+T will open a new terminal tab.
    – GabrielF
    Jan 6, 2014 at 15:15
  • 2
    It is a new terminal... but in a new tab rather than new window.
    – GabrielF
    Jan 6, 2014 at 15:18
  • 1
    I don't see any reason to use xdotool key ctrl+shift+n while using gnome-terminal you have many other options; see man gnome-terminal in this sense. Jan 6, 2014 at 15:47
  • 2
    Ctrl+Shift+N will open a new terminal window.
    – Siddhartha
    Apr 15, 2015 at 3:07
  • Still think this neat :) is there any equivalent for Mir or Wayland (for implementations not compatible with X server stuff)
    – Wilf
    Jan 6, 2017 at 12:54
1

The following script will open a new tab in the current gnome-terminal window and optionally give that tab a title. This works from any window, you don't have to be in a gnome-terminal window to run it. And, if there is no gnome-terminal running, it will start one. The only caveat is that if you changed the hotkey for opening a new tab you might have to change the line xdotool key ctrl+T to use your hotkey instead.

#!/bin/bash

DELAY=1
# get title we are going to set tab too, default to Terminal
title="Terminal"
if [ $# -eq 1 ]; then
    title="$1"
fi    

# get pid of running terminal server
TPID=$(ps -C gnome-terminal-server -o pid | tail -1 | sed -e's/\s//g')
if [ ${TPID} == "PID" ]; then
    # no terminal process running yet, so just start one
    gnome-terminal -t "$title" --tab
    exit 0
fi

# there is a terminal, get window id of the running terminal server
WID=$(wmctrl -lp | awk -v pid=$TPID '$3==pid{print $1;exit;}')
# get title of currently active tab
TTITLE=`xwininfo -id 0x5000006 | grep xwininfo | awk '{print $5;exit}'`
if [ "$TTITLE" == "\"Terminal\"" ]; then
    # so we don't go into an infinite loop later
    TTITLE="we had a terminal named terminal $$"
fi
# get focus on active terminal tab
xdotool windowfocus $WID
# use keyboard shortcut to open new tab
xdotool key ctrl+T

# see if we have created tab and are in terminal
NTITLE=`xwininfo -id 0x5000006 | grep xwininfo | awk '{print $5;exit}'`
waited=0
while [ "$TTITLE" == "$NTITLE" ]; do
    # sleep for 1 second before we try again
    xdotool sleep 1
    NTITLE=`xwininfo -id 0x5000006 | grep xwininfo | awk '{print $5;exit}'`
    if [ $waited == 0 ]; then
    echo "Waiting "
    waited=1
    fi
    echo -n "."
done    
if [ $waited == 1 ]; then
    echo ""
fi    

# active tab is the new one we created, wait DELAY seconds just to be sure we can type into it to set tab name
xdotool sleep $DELAY
xdotool type --clearmodifiers "termtitle $title"
xdotool key Return
# make tab the active window and raise it to top
wmctrl -i -a $WID
exit 0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .