Home [Linux] Installation, Usage and Commands of tmux
Post
Cancel

[Linux] Installation, Usage and Commands of tmux

tmux

tmux stands for Terminal Multiplexer. When using Linux in the terminal, there can be inconvenience when sessions are disconnected, causing processes in progress to be interrupted or work to be lost. tmux addresses such inconveniences. Additionally, it provides features like window splitting and session sharing, making it a useful tool for a more efficient Linux experience.

tmux Installation

For Debian-based systems, tmux can be installed using the following command:

1
$ sudo apt-get install -y tmux

tmux Terminology

Before diving into the usage and commands, let’s clarify some terminology used in tmux:

  • session: The execution unit created through tmux. Multiple sessions can be created, and each session can be attached/detached. It’s important to note that detaching doesn’t interrupt the work; it continues to run in the background.
  • window: Sessions consist of multiple windows, which can be used like tabs within a session.
  • pane: Within a window, the screen can be divided, and each division is called a pane.

tmux Session Commands

Session Creation Commands

1
$ tmux

To create a session, simply use the command above. By default, sessions are named starting from 0. If you want to specify a session name, you can use the -s option as shown below:

1
2
$ tmux new -s <session-name>
$ tmux new-session -s <session-name>

Session Attach/Detach

Upon session creation, you automatically enter that session. To detach from a session, use the following command:

1
2
# Detach from the session
[Ctrl] + b, d

Press [Ctrl] and b simultaneously, then quickly press d. To reattach to the session, use the following command:

1
2
# Attach to the session
tmux attach -t <session-number-or-name>

List Sessions

1
2
# List sessions
tmux ls

End Session

As mentioned earlier, detaching doesn’t make the session disappear; it continues to run in the background. If you want to end a session, use the following commands:

1
2
3
# End within the session
# -> Executed in the last window, last pane
$ exit
1
2
# End from outside the session
$ tmux kill-session -t <session-name>

tmux Window Commands

1
2
3
4
5
# Executed outside the session
# Create a new window along with session creation
$ tmux new -s -n
# Or specify a name
$ tmux new -s <session-name> -n <window-name>
1
2
3
4
5
6
7
# Executed within the session
[Ctrl] + b -> c : Create a new window
[Ctrl] + b -> d : Close the current window
[Ctrl] + b -> p : Move to the previous window
[Ctrl] + b -> n : Move to the next window
[Ctrl] + b -> , : Rename the current window
[Ctrl] + b -> w : List all windows in the current session

tmux Pane Commands

Pane commands are primarily used for layout-related tasks such as screen splitting and resizing.

1
2
# Split the screen horizontally
[Ctrl] + b, %
1
2
# Split the screen vertically
[Ctrl] + b, "
1
2
3
4
5
6
7
8
# Move between panes - by the number displayed on the screen
[Ctrl] + b, q

# Move between panes - in order
[Ctrl] + b, o

# Move between panes - using arrow keys
[Ctrl] + b, <arrow-key>
1
2
# Adjust pane size - maximize the focused pane (run again to revert)
[Ctrl] + b, z
1
2
3
# Adjust pane size
[Ctrl] + b, :
resize-pane -L or -R or -U -D
1
2
# Change pane layout (switch to various layouts automatically)
[Ctrl] + b, spacebar
1
2
3
# Delete a pane
[Ctrl] + d
[Ctrl] + b, x

Reference

https://hbase.tistory.com/200
https://velog.io/@kth811/tmux-%EC%82%AC%EC%9A%A9%EB%B2%95-%EC%A0%95%EB%A6%AC
https://velog.io/@piopiop/Linux-tmux%EB%A5%BC-%EC%82%AC%EC%9A%A9%ED%95%B4%EB%B3%B4%EC%9E%90

This post is licensed under CC BY 4.0 by the author.