Naming tmux sessions | Generated by AI
Question: How to create tmux sessions with a name?
Answer:
To create a tmux session with a custom name, use the -s flag with the tmux new-session command (or its shorthand tmux new).
Basic Command
tmux new-session -s session_name
Example:
tmux new-session -s myproject
This creates a new tmux session named “myproject” and attaches to it immediately.
Shorthand Version
tmux new -s myproject
Additional Useful Options
- Start detached (create the session in the background without attaching):
tmux new -s myproject -d - Specify a working directory:
tmux new -s myproject -c ~/projects/myapp -d - Run a command on session start:
tmux new -s myserver -c ~/projects -d "python run_server.py"
Common Workflow Examples
- Create and attach:
tmux new -s dev - Create detached (useful in scripts or when you want to set up multiple sessions first):
tmux new -s frontend -d tmux new -s backend -d tmux new -s database -d - Attach to an existing named session:
tmux attach -t myproject - List all sessions (to see names):
tmux list-sessionsor the shorter:
tmux ls
Inside an Existing tmux Session
If you’re already inside tmux and want to create a new named session:
- Press
Ctrl+b(default prefix) then type:new -s newnameand press Enter.
Renaming an Existing Session
tmux rename-session -t oldname newname
or inside tmux: Ctrl+b then :rename-session newname
Pro Tips
- Session names should be descriptive but short (e.g.,
web,api,logs,project-v2). - You can use underscores
_or hyphens-in names. - To kill a session:
tmux kill-session -t session_name
This method works on Linux, macOS, and any system with tmux installed.
References: