Can I script several bash/sh instructions to open and run in separate tmux panes?

I have about 5 or so different commands that need to be executed simultaneously or consecutively.

I usually type them all out manually in their separate panes; I have a bit of a custom layout going on.

1 Answer 1


If you are already in tmux session, you can execute some command in new window like below:

$ tmux neww {command}

Also, if you want to split window and execute command:

$ tmux splitw {command}

Here's some example of running tail -f for several files in the log directory:

$ find logs/ -name '*.log' | xargs -n1 -I{} bash -c 'tmux splitw "tail -f $1"; tmux select-layout main-vertical' -- {}

tmux select-layout part is for fixing pane layout.

added as per comment:

You can use:

$ tmux new {command}

If you aren't in tmux session. So you can combine these like this.


tmux new -s foo "bash tmux-test.sh; wait"


tmux neww htop
tmux neww htop
tmux splitw htop

and then execute test.sh

  • 1
    Cool, but what if I'm not already in a tmux session? I'd like to have it saved it as a .sh script (or similar), if possible. I think you might be onto something here. Thanks!
    – voices
    Jun 2, 2016 at 11:29
  • Windows and panes that are opened in above commands, will close when that {command} terminates. For instance tmux new date launches new window that executes date, and then since date command terminates immediately, tmux session is also terminated.
    – ktsujister
    Jun 2, 2016 at 11:57
  • Doesn't work for me.
    – BonsaiOak
    May 4, 2017 at 17:01

You must log in to answer this question.

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