red0orange

red0orange

Basic Usage of tmux

Content#

From a usage perspective, tmux is a terminal nested within a terminal. First, let's introduce the installation and basic usage of tmux, and then discuss specific usage scenarios.

Installation and Basic Usage of tmux#

tmux is a software. In Ubuntu, run sudo apt-get install tmux to install the software.

Basic commands for using tmux:

  • Before entering tmux:
    • tmux new -s <name>: Create and enter a new tmux session, specifying the name as <name>.
    • tmux a -t <name>: Enter an existing session named <name>.
    • tmux kill-session -t <name>: Close a session.
    • tmux rename-session -t <old-name> <new-name>: Rename a session.
  • After entering tmux:
    • tmux detach: Exit the current tmux session and run it in the background.
    • Press Ctrl+B, then press double quotation marks ": Split the screen vertically and create a new sub-terminal.
    • Press Ctrl+B, then press percent sign %: Split the screen horizontally and create a new sub-terminal.
    • Press Ctrl+B, then press any arrow key: Switch between sub-terminals.

Using tmux for Background Running#

tmux is very suitable for use when remotely connecting to a server. When we remotely connect to a server, we often cannot guarantee that a connection will exist for a long time (for example, network fluctuations may require reconnection). When we need to run a long-running program (for example, downloading a large file with wget), running it directly in the remote connection is prone to interruption. tmux can be used to solve this type of problem, and the method is simple.

  • First, create and enter a tmux session: tmux new -s <name>.
  • Run the program in this session.
  • Split the screen and create a sub-terminal (Ctrl+B + % or "), then enter tmux detach to suspend it in the background.
  • Check the progress by entering: tmux a -t <name>.

Ref#

Notes:

  • Other system tools: [[1_zsh]]
Loading...
Ownership of this post data is guaranteed by blockchain and smart contracts to the creator alone.