1

I need to launch several commands in parallel, each in their own tmux window in the same session, making sure that there is only one instance of each command running.

Ideally, the windows would follow a fixed naming and order so that it's easy to identify them.

I think that in the past I used to do something like this:

tmux new-window -t cmd1 -n cmd1 { my command }

Then tmux would create a window in the last session, named cmd1 and in first position (followed by cmd2 etc.), or do nothing if the window already existed.

0

It works for me if I use an actual integer as index:

$ tmux new-window -t 1 -n cmd1 -d sleep 60
$ tmux new-window -t 1 -n cmd1 -d sleep 60
create window failed: index in use: 1

With a non-integer index it won't work:

$ tmux new-window -t cmd1 -n cmd1 -d sleep 60
can't find window i1

Quotation from the man page (tmux 2.5-4):

 new-window [-adkP] [-c start-directory] [-F format] [-n window-name] [-t target-window] [shell-command]
               (alias: neww)
         Create a new window.  With -a, the new window is inserted at the next index up from the specified target-window, moving windows up if necessary, otherwise target-window is the new window location.

         If -d is given, the session does not make the new window the current window.  target-window represents the window to be created; if the target already exists an error is shown, unless the -k flag is used, in which case it is destroyed.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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