Tmux: Difference between revisions

From UMIACS
Jump to navigation Jump to search
(Created page with "=== Introduction === tmux is a terminal multiplexer for Unix-like operating systems. It allows multiple terminal sessions to be accessed simultaneously in a single window. It...")
 
No edit summary
Line 9: Line 9:
  # tmux new -s $mysession
  # tmux new -s $mysession


tmux operates using a system of [[#Tmux|Windows]] and Panes.
If you need to end your ssh session, but want your processes to keep running you can detach the screen session by using:
 
# Ctrl + b d
===Windows===
Then exit as normal.
Info for Windows
 
===Panes===
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:
If you have multiple screen sessions you can detach and reattach them at any time. To list the current screen sessions running, use:
  # screen -ls
  # tmux ls


The output will be similar to this:
The output will be similar to this:
  # claw@idaho:~$ screen -ls
  # user@machine:~$ tmux ls
  # There are screens on:
  # session1: 1 windows (created Thu Oct 22 10:11:44 2020)
  # 26598.screenTest1 (Detached)
  # session2: 1 windows (created Thu Oct 22 10:11:52 2020)
  # 18457.pts-0.idaho (Detached)
  # session3: 1 windows (created Thu Oct 22 10:11:58 2020)
# 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’
To reconnect to a specific tmux session you may use the attach command:
  # claw@idaho:~$ screen -r 26598
  # user@machine:~$ tmux a -t mysession


or
or


  # claw@idaho:~$ screen -r screenTest1
  # user@machine:~$ tmux attach -t mysession
 
===tmux Architecture===
tmux operates using a system of [[Tmux#Windows|Windows]] and [[Tmux#Panes|Panes]].
Each window can house multiple panes within it.


===Windows===
In tmux, Windows show up at the bottom of your session with a name and a sort number.


===Common Keyboard Shortcuts===
You can create a new window in your session by using:
Ctrl-A is the metacharacter for commands in screen; press it before every key command. Some useful commands in screen:
# Ctrl-b c
You can navigate to the next window using:
# Ctrl-b n
You can navigate to the previous window using:
# Ctrl-b p
You can rename the current window using:
  # Ctrl-b ,
You can close the current window using:
# Ctrl-b &


* Ctrl-A + c (Creates a new window.)
===Panes===
* Ctrl-A + d (detach from current session)
Info for Panes
* 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 [http://www.gnu.org/software/screen/manual/screen.txt  here] to see a full list of Ctrl-A commands (Section 5.1: Default Key Bindings).


=== Important Notes ===
===Copy Mode===
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
In order to navigate around a page in tmux, You must first enter ''Copy Mode'' and then you can start navigating: 
# 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.


=== .screenrc ===
To enter Copy Mode use:
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 [http://www.gnu.org/software/screen/manual/screen.txt  here] for more information about screen commands (Section 5.2: Command Summary).
  # Ctrl-b [
Once in Copy Mode, you can navigate normally using the arrow keys as well as other functions.


=== Useful Links ===
To go to the top of the page type:
* [http://www.gnu.org/software/screen/ The main page at www.gnu.org.]
# g
* [http://www.gnu.org/software/screen/manual/screen.txt GNU Screen documentation] (also accessed through '''man screen''').
To go to the bottom of the page type:
# G

Revision as of 14:47, 22 October 2020

Introduction

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.

Usage

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

If you need to end your ssh session, but want your processes to keep running you can detach the screen session by using:

# Ctrl + b 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, use:

# tmux ls

The output will be similar to this:

# user@machine:~$ tmux ls
# session1: 1 windows (created Thu Oct 22 10:11:44 2020)
# session2: 1 windows (created Thu Oct 22 10:11:52 2020)
# session3: 1 windows (created Thu Oct 22 10:11:58 2020)

To reconnect to a specific tmux session you may use the attach command:

# user@machine:~$ tmux a -t mysession

or

# user@machine:~$ tmux attach -t mysession

tmux Architecture

tmux operates using a system of Windows and Panes. Each window can house multiple panes within it.

Windows

In tmux, Windows show up at the bottom of your session with a name and a sort number.

You can create a new window in your session by using:

# Ctrl-b c

You can navigate to the next window using:

# Ctrl-b n

You can navigate to the previous window using:

# Ctrl-b p

You can rename the current window using:

# Ctrl-b ,

You can close the current window using:

# Ctrl-b &

Panes

Info for Panes


Copy Mode

In order to navigate around a page in tmux, You must first enter Copy Mode and then you can start navigating:

To enter Copy Mode use:

# Ctrl-b [

Once in Copy Mode, you can navigate normally using the arrow keys as well as other functions.

To go to the top of the page type:

# g

To go to the bottom of the page type:

# G