tmux is a terminal multiplexer for Unix-like operating systems. It allows multiple terminal sessions to be accessed simultaneously in a single window. It is useful for running more than one command-line program at the same time. It can also be used to detach processes from their controlling terminals, allowing remote sessions to remain active without being visible.
To invoke a new tmux session, simply use the following command in a terminal:
# tmux new
You can also name the session using the -s flag:
# tmux new -s $mysession
tmux operates using a system of Windows and Panes.
Info for Windows
Info for Panes
If you need to end your ssh session, but want your processes to keep running you can detach the screen session with:
# screen -d
Then exit as normal.
If you have multiple screen sessions you can detach and reattach them at any time. To list the current screen sessions running on a host use:
# screen -ls
The output will be similar to this:
# claw@idaho:~$ screen -ls # There are screens on: # 26598.screenTest1 (Detached) # 18457.pts-0.idaho (Detached) # 2 Sockets in /var/run/screen/S-claw.
To reconnect to a specific screen session you may use either the screen number or name to reconnect using ‘screen -r’
# claw@idaho:~$ screen -r 26598
# claw@idaho:~$ screen -r screenTest1
Common Keyboard Shortcuts
Ctrl-A is the metacharacter for commands in screen; press it before every key command. Some useful commands in screen:
- Ctrl-A + c (Creates a new window.)
- Ctrl-A + d (detach from current session)
- Ctrl-A + [0-9] (Switches to the window corresonding to the number, window 0 is the first window initialized by screen.)
- Ctrl-A + " (Presents a selection of screen windows from which to choose.)
- Ctrl-A + Shift-A Rename the current screen window
- Ctrl-A + <SPC> / Ctrl-A + <BKSPC> (Switch to the next / previous window.)
- Ctrl-A + k (Kill the current window.)
- Ctrl-A + \ (Kill the screen session and all its windows.)
See the documentation here to see a full list of Ctrl-A commands (Section 5.1: Default Key Bindings).
If you start a screen session that will run a program within a session that has only one window, such as by issuing the command
# screen program.c
then when the program exits the screen session will terminate as well. This has the potential to hide any output you may want from your program since the screen session will exit. To solve this issue you can either make sure your shell is not set to auto-logout, or ensure that you have multiple windows open in the screen session so that it will not terminate when the program exits.
Similar to .bashrc, the file .screenrc in a user's home directory can be used to customize a screen session's startup behavior. Commands listed in this file will be executed upon starting screen, and can be useful to set up your environment to display important information such as the window number and name, the name of the host you're connected to, or altering the key sequences for screen commands. See the link here for more information about screen commands (Section 5.2: Command Summary).
- The main page at www.gnu.org.
- GNU Screen documentation (also accessed through man screen).