1

I know that gnome-terminal will open a new window, I wondered is there a way to open a new tab, not just a new window?

After this, is there a way to pass a command to the new window for example

gnome-terminal && cd /

Which will result in

  1. New Terminal Opens
  2. New Terminal then runs cd /

[Edit] Will these answers will say how to pass cmds to another terminal, it does not answer how to open a new TAB. Which is what I am after, I do not want more than one terminal open.

3

GNOME Terminal offers no generic command line solution to open a new tab in an already existing window.

(Why? Because it may have multiple windows open, and it wouldn't know in which one to open the new tab. You might say you only have one window, but if such a feature was implemented, the software would need to be consistent and need to do something reasonable when it had multiple windows, which it couldn't really do.)

Hacks, such as simulating the user pressing a key, exist as per an already filed answer, but work only under X.Org, not under Wayland.

Beginning with forthcoming version 3.28, the command gnome-terminal --tab will open a new tab in the GNOME Terminal window where this command is executed from, if this command is executed from within GNOME Terminal.

(How does it know in which window to open the new tab in this case? It knows by setting a certain environment variable upfront to a different value in each of the terminals it opens. That environment variable lets it locate the desired window.)

| improve this answer | |
2

You must simulate pressing shift + ctrl + T in the terminal. Programs exist to doing that:

If you want to do it from the command line

For example you can use xdotool - a program that lets you simulate keyboard input.

sudo apt-get install xdotool

then type in the terminal:

xdotool key ctrl+shift+t

That will simulate pressing the key combination.

| improve this answer | |
  • But then how do I pass a command to the newly opened window? Thanks btw – Jamie Hutber Jan 26 '18 at 14:37
  • If it's possible you can add the command to your ~/.bashrc file. Every time terminal opens this file is invoked. – Mahdi Jan 26 '18 at 14:45

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