JavaScript must be enabled in order for you to see "WP Copy Data Protect" effect. However, it seems JavaScript is either disabled or not supported by your browser. To see full result of "WP Copy Data Protector", enable JavaScript by changing your browser options, then try again.

介紹Unix/Linux神器之一:Tmux


最近看到joseph介紹Tmux(踢馬克思)的文章,雖然我沒使用過GNU的Screen,不過還是介紹一下它的優點,一是Session可以被多個SSH同時連線,與Screen斷線後要做Detach轉Attach有所不同,二來在Tmux可以快速做Session的轉換(C-b+s),與Screen轉換前必須先做Detach的做法不一樣,最後Tmux還可以做自由地水平或垂直的Pane分割並Resize,與Screen的只能做單一水平分割的限制有很大的差異,所以廢話不多說,在實作前可以先參考下面兩張關於Tmux和Screen的架構流程做個比較,如下:

1) 安裝tmux套件(可直接透過YUM套件庫或RPM套件包做安裝)
#yum install tmux
#rpm -qa | grep -i 'libevent'
libevent-1.4.13-1
#rpm -ivh ./tmux-1.4-3.el5.1.i386.rpm
warning: ./tmux-1.4-3.el5.1.i386.rpm: Header V3 DSA signature: NOKEY, key ID 217521f6
Preparing... ########################################### [100%]
1:tmux ########################################### [100%]

2) Tmux的個人環境設定(參照joseph的設定,但註解掉更改組合鍵的部分)
#vi ~/.tmux.conf
# General configuration.
# $ tmux show-options -g
set -g base-index 1
set -g display-time 5000
set -g repeat-time 1000
set -g status-keys vi
set -g status-utf8 on
set -g status-bg black
set -g status-fg white
set -g status-justify left
set -g status-interval 1
set -g status-left-length 15
set -g status-right-length 55
set -g status-left "#[fg=white,bright,bg=blue] Session #[fg=yellow,bright,bg=blue]#S #[default] |" # session-name
set -g status-right "#[fg=red,bright][ #[fg=cyan]#(cd ~/miiicasa;git branch --no-color | sed -e '/^[^*]/d' -e 's/* //') #[fg=red]]#[default] #[fg=yellow,bright] %Y-%m-%d #[fg=green]%H:%M:%S #[default]#[fg=magenta,bright]#[default]"
# Configuration for each window.
# $ tmux show-window-options -g
setw -g utf8 on
setw -g window-status-format " #I$ #W "
setw -g window-status-current-format " #I$ #W "
setw -g window-status-current-bg yellow
setw -g window-status-current-fg blue
setw -g window-status-current-attr default
# Customization for key bindings.
# Check it using "C-a + ?".
## Make tmux like screen, using Ctrl+A
#unbind C-b
#set -g prefix ^A
#bind a send-prefix
## Use h and v for splitting.
#unbind %
#unbind '"'
#bind v split-window -h
#bind | split-window -h
#bind h split-window -v
#bind - split-window -v
## Use a for renaming the window prompt.
#unbind ','
#bind ` command-prompt -I '#W' "rename-window '%%'"

3) 常用組合鍵的介紹與說明
Default作用鍵:Ctrl-b
作用鍵+c:建立一個新的視窗
作用鍵+d:切斷目前Session的連線
作用鍵+p/n:切換到上/下一個視窗
作用鍵+0~9:切換至第0~9個視窗
作用鍵+s:可切換不同的Session
作用鍵+!:將目前的pane抽出來做獨立視窗
作用鍵+":切割出一個水平pane
作用鍵+%:切割出一個垂直pane
作用鍵+方向鍵:切換至所對應的pane
作用鍵+x:關閉目前所在的pane
作用鍵+空白鍵:重新配置分割的pane(水平<->垂直)
作用鍵+ESC+方向鍵:會依照所對應的方向調整視窗大小
作用鍵+Ctrl-z:將該Session暫停,可用fg撿回來
作用鍵+Ctrl-o:會將所有pane的內容順時針做替換
作用鍵+,:可以修改目前視窗的名稱以方便辨認
作用鍵+.:可以修改目前視窗的編號以方便排序
作用鍵+?:查詢所有組合鍵的功能,如下:
C-b Send the prefix key (C-b) through to the application.
C-o Rotate the panes in the current window forwards.
C-z Suspend the tmux client.
! Break the current pane out of the window.
" Split the current pane into two, top and bottom.
# List all paste buffers.
% Split the current pane into two, left and right.
& Kill the current window.
’ Prompt for a window index to select.
, Rename the current window.
- Delete the most recently copied buffer of text.
. Prompt for an index to move the current window.
0 to 9 Select windows 0 to 9.
: Enter the tmux command prompt.
; Move to the previously active pane.
= Choose which buffer to paste interactively from a list.
? List all key bindings.
D Choose a client to detach.
[ Enter copy mode to copy text or view the history.
] Paste the most recently copied buffer of text.
c Create a new window.
d Detach the current client.
f Prompt to search for text in open windows.
i Display some information about the current window.
l Move to the previously selected window.
n Change to the next window.
o Select the next pane in the current window.
p Change to the previous window.
q Briefly display pane indexes.
r Force redraw of the attached client.
s Select a new session for the attached client interactively.
L Switch the attached client back to the last session.
t Show the time.
w Choose the current window interactively.
x Kill the current pane.
{ Swap the current pane with the previous pane.
} Swap the current pane with the next pane.
~ Show previous messages from tmux, if any.
Page Up Enter copy mode and scroll one page up.
Up, Down
Left, Right
Change to the pane above, below, to the left, or to the right of the current pane.
M-1 to M-5 Arrange panes in one of the five preset layouts: even-horizontal, even-vertical, main-horizontal,
main-vertical, or tiled.
M-n Move to the next window with a bell or activity marker.
M-o Rotate the panes in the current window backwards.
M-p Move to the previous window with a bell or activity marker.
C-Up, C-Down
C-Left, C-Right
Resize the current pane in steps of one cell.
M-Up, M-Down
M-Left, M-Right
Resize the current pane in steps of five cells.
Key bindings may be changed with the bind-key and unbind-key commands.

4) 在Shell中的常用的操作
#tmux <-開啟一個新的Tmux Session
#tmux ls <-列出主機上所有的Tmux Session
#tmux a -t 0 <-將背景中第0個Tmux Session撿回來,這裡的a代表attach

◎以下就是關於Tmux的簡易介紹,至於GNU/Screen詳細的使用介紹,可參考這邊文章,收工!

Leave a Comment


NOTE - You can use these HTML tags and attributes:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

 
This site is protected by WP-CopyRightPro