screen 用法小记

screen 也是早就会用的工具,但发现近来一段时间不用,就知道 ^a^a 和 detach attach 这些简单的命令了。同样的情况还有 tmux、svn、git,学习的时候一是觉得知识简单,二十觉得经常在用,不可能忘掉。可知世事无常,好记忆总不如烂博客,于是吃一见长一智,来个亡羊补牢罢。

第一步,启动 screen:

screen

或者启动时执行一条 shell 命令:

screen vim notification.py

启动选项:

screen -c: 指定 screen 配置文件,默认配置文件是~ HOME/.screenrc

screen -d: detach screen, 在 screen 会话里使用,等同于 ^a d

screen -r [pid.sessionname]: resume a detached screen

screen -R: resume first appropriate screen session

screen -e ^xy: 将 ctrl+x 设置为控制字符,如果输入 ctrl+x,则认为输入了 y(Set the command character to x, and the character generating a literal command character (when typed after the command character) to y. The defaults are C-a and a, which can be specified as ‘-e^Aa’),默认设置是 -e^Aa

screen -h num: 设置 defscrollback,即滚动条缓冲区大小

screen -ls or -list: 显示所有的 screen session

screen -wipe: 同 screen -ls 一样,但会清除已经死掉的 session

screen -S sessionname: 设置 sessionname

screen -v: print version information

screen -x: attach to a session which is already attached elsewhere (multi-display mode). Screen refuses to attach from within itself. But when cascading multiple screens, loops are not detected; take care.

screen 配置:

screen 配置来自三个地方:

  1. 默认配置,来自~ HOME/.screenrc 和 / usr/local/etc/screenrc 文件

  2. 通过指定配置文件获取配置: screen -c xxx

  3. screen 运行过程中通过 colon 交互式修改配置文件

缺省 screen 配置:

C-a ‘: 选择 screen 窗口,输入数字,回车确认

C-a “: 出现窗口列表,回车选择

C-a 0..9-: 选择 0~9 号窗口,或者 – 窗口

C-a c 或者 C-a C-a: 创建窗口

C-a d 或者 C-a C-d: detach screen

C-a k 或者 C-a C-k: kill current window

C-a n 或者 C-a C-n: switch to next window

C-a N: switch to window N, N is window index

C-a p 或者 C-a C-p: switch to previous window

C-a t 或者 C-a C-t: show load average and xref

C-a w 或者 C-a C-w: show windows list,等同于 C-a ”

C-a ?: show key bindings

C-a [: enter copy mode,空格键开始选择内容,再次空格选择完毕

C-a ]: paste,首先要进入 insert 模式

screen 配置文件:

如果要想学习这部分内容,首先要能够看明白 screen 的各种命令选项,参考:http://www.gnu.org/software/screen/manual/screen.html#Command-Summary

发布者

胡中元

《中原驿站》站长

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注