unityやgnomeなどX-Windowを使っていると、端末のコンソールをタブで複数切り替えながら使用したりすると思いますが、TeraTermなど、1つの端末画面で複数のセッションを切り替えたり、カット&ペーストを行うことができる非常に便利なコマンドがあります。
また、RS-232Cの接続を行う際にも用いることができます。
それが、今回ご紹介する screen コマンドです。
ちなみに、screen コマンドのフロントインターフェイス、 byobu と言うのもあるそうです。
日本語 man ページ(新しいウィンドウが開きます)
ちなみに、RHEL6には、デフォルトでインストールされていませんので、下記に示すコマンドでインストールをしてください。
yum install screen
ubuntuの場合には、下記のコマンドでインストールできます。
apt-get install screen
では、実際の操作の説明です
このコマンドは、各ユーザ毎に使用できます。
> screen [ENTER]
CTRL + a (規定キーバインド時 設定変更可)
下記に記載しているキーは、CTRL + a + A (CTRLキーと a を押した後、SHIFT + A を押す。)というキー入力となります。
自分のホームディレクトリに、.screenrcファイルを作成して各種パラメータを設定していくことにより、自分好みの環境を構築することができます。
推奨.screenrc設定
autodetach on
defscrollback 2048
vbell off
termcapinfo xterm 'is=\E[r\E[m\E[2J\E[H\E[?7h\E[?1;4;6l'
caption always "%{= wb} %-w%{=bu dr}%n %t%{-}%+w %= %{=b wk} [%l] %{=b wb}%y/%m/%d %{=b wm}%c"
bind l windowlist
altscreen on
startup_message off
#あると便利なキー割り当て
bind key -k k1 select 0
bind key -k k1 select 1
bind key -k k2 select 2
bind key -k k3 select 3
bind key -k k4 select 4
bind key -k k5 select 5
bind key -k k6 select 6
bind key -k k7 select 7
bind key -k k8 select 8
bind key -k k9 select 9
bind key -k k; screen
bind key -k F1 title
bind s eval split focus "select 0"
bind ^s eval split focus "select 0"
bind r eval 'command -c resize'
bind ^r eval 'command -c resize'
bind + eval 'command -c resize'
bind - eval 'command -c resize'
bind -c resize + eval 'resize +1' 'command -c resize'
bind -c resize - eval 'resize -1' 'command -c resize'
captionの説明
caption always '%?%F%{= gW}%:%{= Kk}%?%2n%f%07=%t%='
# caption string description:
#
# %? - Start of a conditional statement.
# %F - Use this part of the statement if the window has focus (i.e. it
# is the only window or the currently active one).
# %{= gW} - bright white on green.
# %: - else
# %{= Kk} - bright black on black
# %? - End conditional statement.
# %2n - number of the current window with left 2 padding
# %f - flags for current window
# %07= - left 7 padding for window number and flags
# %t - title of current window
# %= - truncation/padding point
screenコマンドには、上記に上げた便利な使い方の他に、L3-Switchやルータなど、ネットワーク機器を設定する際に必須とされるRS-232C接続を行うことができます。
以下にその設定方法を紹介します。
screen /dev/ttyS0 9600
接続先デバイス名と、接続転送速度を指定して起動させます。
ただし、この方法を用いた場合、複数の接続を行うことができるかどうかは、現時点では確認できていません。
※Ubuntuの場合、各種デバイスをroot権限でないとアクセス駅なようなので、下記のように実行します。
sudo screen /dev/ttyS0 9600