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
- New Terminal Opens
- 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.
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.)
So for your particular case, you could do:
This way you get a running shell in the new tab once the
cd /
is completed. If you just didgnome-terminal --tab -- some command
, then the tab will close immediately aftersome command
exits. By usingbash -c 'some command; exec bash'
instead, the tab will have a runningbash
process oncesome command
completes.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.then type in the terminal:
That will simulate pressing the key combination.