how can I open a extra console and run a program in it with one command?

I would prefer to use the option -x that provides more reliable work than -e:

gnome-terminal -x bash -c "<my command or script>; exec bash"
  • The option -x means --execute - the remainder of the command line inside the terminal.

  • And our command is bash -c "<commands>". That means we execute a new bash shell, which should run some -c "<commands>".

  • We have two separated (by semicolon ; == new line) <commands>.

  • The first command <my command or script> will execute that we want.

  • The second command exec bash has a meaning - remain open the current gnome-terminal window. There are another possible approaches to do that. In the current case the command exec will replace the current process image with a new process image - in other words it will 'kill' the current process and will execute a new (bash) under the current PID.


Update: The -x/-e syntax is now deprecated - Ubuntu 18.04. The new recommended way is :

gnome-terminal -- bash -c "<my command or script>; exec bash"
  • If you want to reach the users home directory within the above command use the environment variable $HOME: bash -c "cd $HOME/; ..."

More examples of usage of this format:

  • Open a new terminal and source scripts
  • Launch gnome-terminal from SSH session to Desktop session
  • Start Specific Terminal on Startup
  • Crontab and C program that should be executed into a terminal window
  • Xdotool does not minimize terminal window when using in Startup Application when pc boots?