Creating a tmux session without attaching to it

tmux

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.

Best Answer

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
Related Question