22

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.

1 Answer 1

24

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
3
  • What about being able to name that session? I tried: tmux new -s {name} -d and that didn't work.
    – innectic
    Aug 21, 2016 at 20:23
  • @innectic Looks like tmux new -d -s <name> works Aug 21, 2016 at 20:27
  • @innectic See updated answer Aug 21, 2016 at 20:29

You must log in to answer this question.

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