tmux session management commands: tmux new-session -s name
(create), tmux attach -t name
(attach), tmux ls
(list), tmux kill-session -t name
(delete), Ctrl+b d
(detach), Ctrl+b $
(rename).
tmux new -s dev
Sessions are the core organizational units in tmux. A session can contain multiple windows, and each window can contain multiple panes. Effective session management is key to a productive tmux workflow.
# Create a new session named "dev" $ tmux new-session -s dev # Short form $ tmux new -s dev # Create a new session and run a command $ tmux new -s logs -d 'tail -f /var/log/system.log' # Create a new session with specific window name $ tmux new -s project -n editor
# List all sessions $ tmux list-sessions # Short form $ tmux ls
# Attach to a session named "dev" $ tmux attach-session -t dev # Short form $ tmux a -t dev # Attach or create if it doesn't exist $ tmux new-session -A -s dev
To detach from the current session (leaving it running in the background):
# Using key binding Ctrl+b d # Using command Ctrl+b :detach
# Using key binding Ctrl+b $ # Using command Ctrl+b :rename-session new_name
# List sessions and select interactively Ctrl+b s # Switch to next session Ctrl+b ) # Switch to previous session Ctrl+b (
# Kill a specific session $ tmux kill-session -t dev # Kill all sessions except the current one $ tmux kill-session -a # Kill all sessions except "dev" $ tmux kill-session -a -t dev
For persistent sessions across system reboots, install the tmux-resurrect and tmux-continuum plugins:
# In your ~/.tmux.conf set -g @plugin 'tmux-plugins/tpm' set -g @plugin 'tmux-plugins/tmux-resurrect' set -g @plugin 'tmux-plugins/tmux-continuum' # Enable automatic restore set -g @continuum-restore 'on'