Tmux study summary 1 - Using the default configuration for basic operation

tmux is running on a Unix OS X and split-screen terminal software Terminal Multiplexer .

And represents a key rule shortcuts

  • CTRL-b: Press the CTRLkey and bkey
  • CTRL-R: Press CTRL, SHIFTand rkey
  • CTRL-b d: Press the CTRLkey and the bkey, release it, and then quickly press the dbutton

installation

On OS X:

$ brew install tmux

On Debian and Ubuntu:

$ sudo apt-get install tmux

Determine if the installation was successful:

$ tmux -V

Open tmux

Open tmux simply enter the command:

$ tmux

After performing tmux opens a session, and the session as a common terminal, and execute any command can be entered in it.

To return from the tmux ordinary session to a terminal, enter the command:

$ exit

More use of little use, you should use "named session."

Create a named session

A machine can have multiple sessions, each session is organized to make the deal with its name.

Create a name for the basic session:

$ tmux new-session -s basic

You can also use abbreviated commands:

$ tmux new -s basic

Detachment and associated session

tmux program is a CS mode, when you turn a tmux session, which is a server. All open sessions in this environment and processes by the session management server. When you are "out" and the session because the session is not over yet, these open procedures and processes will continue to run in the background. After that, we can re "associate" of the session, before work continues.

Example:

Create a named session:

$ tmux new -s basic

In this session, open a top command:

$ top

Then use keyboard shortcuts CTRL-b dspun off from the current session, after the detachment will return to normal terminal.

CTRL-b dThe method according to shortcuts is correct: first pressing simultaneously CTRLthe key and bkey prefixing tmux command, and then release all the keys, then quickly press representatives tmux command dkey, the command to tmux d.

Command prefix

tmux default command prefix CTRL-b, denoted PREFIX, you can re-bind the settings.

Re-associate to an existing session

List All session on the current machine:

$ tmux list-sessions

You can also use the shorthand command:

$ tmux ls

This command displays the current only one session:

basic: 1 windows (created Sat Jul 30 09:48:32 2016) [80x23]

To link an existing session, if only one session, then directly:

$ tmux attach

First with PREFIX ddetachment from the current session, and then create a new session but does not automatically associated with:

tmux new -s second_session -d

At this session command lists out there are two sessions:

tmux ls
basic: 1 windows (created Sat Jul 30 09:48:32 2016) [80x23]
second_session: 1 windows (created Sat Jul 30 09:52:31 2016) [80x23]

You can use -t(? Target) option to specify the associated session:

$ tmux attach -t second_session

Close Session

Inside tmux session, you can use exitcommands directly destroy and terminate the current session. It can also be used in ordinary terminal kill-sessionfor:

$ tmux kill-session -t basic
$ tmux kill-session -t second_session

If a session there is a dead program, you can use this method to shut down the entire session.

Multi-window operations

Can run multiple programs at the same time in a tmux session, tmux can use multiple windows in a session of multiple programs orderly organization and management.

When a session is started automatically creates an initial window, after which you can then create more windows in the session.

Create a name for the windows of the session, and the first (default) window is named shell :

$ tmux new -s windows -n shell

Create a new window in the session

In conversation, use the shortcut PREFIX cto create a new window. In the window and run topthe command. Notes that the name of the window is based on running and dynamic. For the convenience of management, they should explicitly named, is in use shortcut keys PREFIX ,, enter the name, such as Processes in the status bar.

Switch between windows session

There will be a focus on the window name of the current window *number. Window switch can use the following shortcuts:

  • PREFIX n: Move to next (reciprocally cycles)
  • PREFIX p: Move to a (reciprocally cycles)
  • PREFIX 编号: Move directly to a number of windows, such as PREFIX 0
  • PREFIX f: According to locate the window name
  • PREFIX w: Shows a window containing a list of names of all windows for selection switching

To close the current window, run directly in the window exitcommand. You can also use shortcuts PREFIX &, it will confirm the operation in the status bar. When all the windows are closed, the session also will be closed.

Multi-pane operation

May be divided into a plurality of window panes. And run different programs in each pane.

Create a new session, multi-pane practice operations:

$ tmux new -s panes

Shortcuts pane splits:

  • PREFIX %: The average level of segmentation
  • PREFIX ": Vertical segmentation Average

Switching focus between pane, shortcut keys PREFIX ocan also be used PREFIX 方向键to switch.

Pane layout templates

Several built-in layout templates:

  • even-horizontal: from left to right average level layout
  • even-vertical: vertical averaging arrangement from top to bottom
  • main-horizontal: a large upper pane, the other in the lower
  • main-vertical: left a large pane, the other on the right
  • tiled: All panes average layout on the screen

You can use shortcut keys to PREFIX SPACEBARturn switch between layout templates.

Close Pane

Use shortcut keys PREFIX x.

Use the command mode

The current shortcut keys are used tmux shortcut commands. i.e., the command can be run tmux terminal command line, and VI may be similar, running in the status line in the command mode.

In the session, enter the command mode with a shortcut PREFIX :, this time, you can run the appropriate command tmux in the status bar, such as creating a new name for the console window: new-window -n console.

Create a named window while performing a "top" command: new-window -n processes "top"After a window when the window is created so the command is completed, the window will automatically close.

to sum up

Shortcuts PREFIX ?list all the shortcuts.

Create a command session:

Command | Description
---------------------------- |
tmux new new-the session | create an anonymous session, may be abbreviated tmux newor direct tmux
tmux new - s devel | create a name for the "devel" session
tmux new -s devel -n editor | create a name for the "devel" sessions, and the first window named "Editor"
tmux the attach -t devel | linked to called "devel" session

Default command on the session window panes

Command | Description
------------- |
PREFIX d | from the session, the session will continue to run in the background
PREFIX: | command mode
PREFIX c | create a new window in the session, the corresponding command tmux new-window
PREFIX 0 ... 9 | window switch in the window according to the number
PREFIX w | show all windows in the current session, choose to switch
the PREFIX, | named current window
PREFIX & | Close this window
PREFIX% | average level of split windows
PREFIX "| vertical averaging window divided
PREFIX o | cycle through the plurality of panes
PREFIX q | display pane number
PREFIX x | off current pane
PREFIX SPACE | before each switching layout pane

Resources:

tmux: Productive Mouse-Free Development

Guess you like

Origin www.cnblogs.com/haiiiiiyun/p/12565404.html