Common `tmux` commands and explanations thereof


Introduction

This tutorial reviews a common `tmux` workflow. The objective is to learn how to catalyze a process in a `tmux` session, exit the session, and return to the running process.


Step 1: Start a New `tmux` Session

1) Open your terminal.
2) Start a new tmux session by typing:

tmux new-session -s mysession
										
Replace mysession with your preferred session name.

Step 2: Run The Process

Once inside the tmux session, run your desired process. For example, execute a Python script:

python myscript.py
										
Replace python myscript.py with any command you want to run.

Step 3: Detach from the `tmux` Session

To detach from the tmux session without stopping the process, press:

Ctrl + b
										
then release and press:

d
										
This will bring you back to the regular terminal while the process continues to run inside the tmux session.

Step 4: List Active `tmux` Sessions (Optional)

To see a list of active tmux sessions, type:

tmux ls
										
This will show you all active sessions along with their names.

Step 5: Reattach to the `tmux` Session

To reattach to the previous session created, type:

tmux attach-session -t mysession
										
Replace mysession with the name of your session.

Step 6: Exit the `tmux` Session

1) To exit and kill the tmux session (this will stop any running processes within that session), type:

exit
										
This will close the `tmux` session and return you to the regular terminal.

2) Alternatively, you can kill the session from outside by typing:

tmux kill-session -t mysession
										

Summary of commands

1) Start a new session:
tmux new-session -s mysession

2) Run a process:
python myscript.py

3) Detach from the session:
Ctrl + b, then d

4) List active sessions:
tmux ls

5) Reattach to the session:
tmux attach-session -t mysession

6) Exit the session:
exit

7) Kill the session:
tmux kill-session -t mysession

Top of page