13

I'm trying to create a new tmux session without attaching to it. Running man tmux shows nothing for this, but there must be someway to do this.

13

You can run

tmux new-session -d

to start the new session in detached mode.

$ tmux list-sessions
failed to connect to server: Connection refused
$ tmux new-session -d
$ tmux list-sessions 
0: 1 windows (created Sun Aug 21 16:18:46 2016) [80x23]

You can run specific commands eg

tmux new-session -d vi

would run vi in the new session, but detached.

$ ps -ef | grep -w vi   
sweh      2313  1906  0 16:20 pts/2    00:00:00 grep -w vi
$ tmux new-session -d vi
$ ps -ef | grep -w vi   
sweh      2317     1  0 16:20 ?        00:00:00 tmux new-session -d vi
sweh      2318  2317  0 16:20 pts/3    00:00:00 vi
sweh      2320  1906  0 16:20 pts/2    00:00:00 grep -w vi

Sessions can be named by specifying the -s flag after the -d

$ tmux new-session -d -s foobar          
$ tmux list-sessions
foobar: 1 windows (created Sun Aug 21 16:27:10 2016) [80x23]

$ tmux attach-session -t foobar
  • What about being able to name that session? I tried: tmux new -s {name} -d and that didn't work. – innectic Aug 21 '16 at 20:23
  • @innectic Looks like tmux new -d -s <name> works – RPiAwesomeness Aug 21 '16 at 20:27
  • @innectic See updated answer – Stephen Harris Aug 21 '16 at 20:29

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.