Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am trying to write a command that will launch a few terminal tabs, execute something in each tab, and have each tab stay open after the command in finished, so I can look at the output and type more commands in each tab

something like this:

gnome-terminal --tab -e "ls -a" --tab -e "ls"

but the problem with this is that the tabs close as soon as the "ls" commands finish. Does anyone know how to make the tabs stay open?

share|improve this question

migrated from Aug 21 '10 at 5:36

This question came from our site for professional and enthusiast programmers.

up vote 11 down vote accepted

Gnome-terminal can either execute a command or open a shell, but not both.

There is a workaround to do both by encapsulating the command and subsequent invocation of the shell into one command.

$ gnome-terminal -e "bash -c \"echo foo; echo bar; exec bash\""

For more alternatives read my answer to a similar question on stack overflow:

share|improve this answer

If you have xdotool and wmctrl installed, then the following shell script might work:

#!/usr/bin/env bash

window="$(xdotool search --class gnome-terminal | head -1)"
xdotool windowfocus $window
xdotool key ctrl+shift+t
xdotool type "$*"
xdotool key Return

I use it like this:

$ run-in-new-tab 'ls -l'

I found this idea on Trustin Lee's blog.

share|improve this answer
Thanks. This works pretty well. I have to add a sleep 1 after the ctrl+shift+t to get it to work for me though. I'll accept this if nothing else comes up soon – Mark Aug 4 '10 at 5:07
Yeah - i found i had to have sleep 2 to make it work 100% of the time. Great solution though - i'm now opening 8 tabs, which ssh into various servers, start various processes etc, using this: my morning setup is now totally scripted :) – Max Williams Feb 21 '13 at 10:00

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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