>[!quote] In a Nutshell >Terminal multiplexer, allows to control a collection of terminals from a single screen. Each collection of pseudo terminals (session) can continue to run in the background, even when e.g. disconnecting from a [[SSH - Secure Shell|ssh]] session. --- #### Basic Usage tmux sessions are managed by a single server, which exits after all sessions are killed. Each session is displayed on screen via a client connecting to the server. Both are separate [[Threads vs. Processes|processes]] communicating via a [[Network Socket|socket]] in the [[which - Search for Executable#The Linux File System|directory]] `/tmp`. **Starting a session** ```bash tmux new-session -s session_name # use flag -d to create in detached mode ``` **Attaching/Detaching to/from a session** ```bash tmux attach-session -t session_name # -t to identify by name ``` To **detach**, use prefix key `Ctrl-b` and then press `d`. **List all sessions** ```bash tmux ls ``` **Kill a session** ```bash tmux kill-session -t session_name # -t to identify by name ``` --- #### Window and Pane Management Windows are like separate tabs within a tmux session, comparable to tabs in a browser. Panes divide a single further into subareas. **Create/Kill a window** When outside a session, use e.g. ``` tmux new-window 'htop' ``` to create a new window running the htop process viewer. When inside a session, use prefix keys: ##### Window Management and Navigation: | **Command** | **Action** | | ------------ | ----------------------------------------------- | | **Ctrl-b c** | Create a new window | | **Ctrl-b d** | Detach from the current session | | **Ctrl-b n** | Switch to the next window | | **Ctrl-b p** | Switch to the previous window | | **Ctrl-b w** | List all windows in the session | | **Ctrl-b ,** | Rename the current window | | **Ctrl-b &** | Kill the current window (asks for confirmation) | ##### Pane Management and Navigation: | **Command** | **Action** | | ---------------- | -------------------------------------------------------- | | **Ctrl-b %** | Split the current window vertically (left/right panes) | | **Ctrl-b "** | Split the current window horizontally (top/bottom panes) | | **Ctrl-b o** | Switch to the next pane | | **Ctrl-b q** | Show pane numbers for quick navigation | | **Ctrl-b x** | Close the current pane (ask for confirmation) | | **Ctrl-b Up** | Move to the pane above | | **Ctrl-b Down** | Move to the pane below | | **Ctrl-b Left** | Move to the pane to the left | | **Ctrl-b Right** | Move to the pane to the right |