Run a Command in a New Detached tmux Session
Start a command in the background with tmux new -d -s name 'command'. The session ends when the command does, unless remain-on-exit is set.
A long job should keep running after you log out, and you want to find it again by name.
tmux new -d -s job 'echo hi; sleep 1'
tmux ls
sleep 2
tmux lsjob: 1 windows (created Fri Nov 6 18:40:28 2026)
no server running on /tmp/tmux-0/defaultWith -d the session starts without attaching, and the shell command after the options runs in its first window. The session lives only as long as that command, so the first tmux ls lists it and the second, after the command has finished, reports that no server is running. This is the documented behavior of new-session. To keep the window and its output after the command ends, run tmux set-option -g remain-on-exit on first.
Output from a job that ended is gone unless the window is kept or the output is also written to a file. For long jobs that must survive reboots, use systemd or cron rather than tmux. Give each session a distinct name, since a second new -s job fails with a "duplicate session" error, and tmux new -A -s job attaches instead.