Attach to tmux session and run a command

tmux

How I can run a command in Tmux when I'm attaching to a session ?

I want attach and immediately run a command.

I read the docs, but found only send keys, which not suits my needs.

Best Answer

You can attach to a running tmux session and spawn a new window which runs a particular command:

tmux attach \; new-window vim

Note that this does not spawn vim in the pre-exsiting window - there is no facility for doing that, it doesn't really make sense: as @Falcon Momot points out, an existing window could be running anything, the only way to issue commands is "send keys".

Related Question