一天一命令-screen
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了一天一命令-screen相关的知识,希望对你有一定的参考价值。
一天一命令-screen
screen
多终端窗口管理器,可以通过该软件同时连接多个本地或远程会话,并自由切换
Use: screen [ -options ] [ cmd [ args ] ] screen -r [[pid.]tty[.host]] screen -r sessionowner/[[pid.]tty[.host]] -A 将所有的窗口都调整为目前终端机的大小 -c file 读取指定配置文件 -d 剥离别处正在运行的会话 -D 剥离并退出远程会话 -h 设置回滚的命令历史大小 -l 记录登录状态(记录到/var/run/utmp),-ln 关闭 -ls 显示所有的会话连接 -L 开启输出日志记录 -m 忽略当前进程变量,建立新的会话 -r [session] 重回剥离的会话 -R 重回剥离的会话,如果找不到则创建新的会话 -s shell 指定建立新会话的shell -S name 创建会话并指定名称 -t title 设置标题 -wipe [match] 清除无法使用的会话 -x 恢复之前的会话
分清终端,会话,窗口的概念
终端:远程开启一个ssh连接,表示开启一个登录终端
会话:开启一个screen会话,如screen -S help表示开启一个会话help
窗口:进入screen会话,可以建立多个窗口,如通过快捷键C-a S可以分割窗口
screen -S help //新建一个会话help screen -ls //列出所有的会话 screen -r num //重新连接指定num或者name的会话,之前的操作依然还在 screen -r help //回到会话help screen -d help //剥离会话help screen -d -r help2 //结束当前会话回到指定会话 exit //退出screen会话,提示信息screen is terminating
screen会话中的快捷键,以下快捷键都是以Ctrl+a开始的,以下均省略,不再说明
Ctrl+a ? 显示所有快捷键
c 创建新的shell窗口并切换,exit关闭或退出
A 重命名当前窗口,输入新名称,然后回车
d 剥离会话,暂时断开当前会话
k 中断当前会话,关闭窗口及窗口中正在运行的进程,同exit
n 切换到下一个窗口
p 切换到上一个窗口
0-9 切换到0-9指定窗口
w 列出当前所有窗口,*号表示当前窗口
如果需要较长时间的操作,可以通过screen命令来避免断网导致命令执行中断:
screen
yes
断开连接,重新连接
screen -ls
screen -r
命令继续执行
exit //命令执行完毕后退出screen窗口
screen远程帮助:
两个终端都通过ssh连接到同一主机
screen -S help //在终端1创建会话help
screen -x help //在终端2加入会话help,可以同时加入多个终端,并且命令都是即时显示的
exit //当有一个终端退出,则screen所有会话都会退出
man screen中的快捷键定义:
The following table shows the default key bindings: C-a ? (help) 查看快捷键列表 C-a ‘ (select) 输入num或name,直接跳转到指定num或name的会话 C-a " (windowlist -b) 显示所有会话列表,方向键选择,回车进入 C-a 0-9 (select 0-9) 选择指定会话,可以先通过C-a w显示所有会话 C-a tab (focus) 切换到下一个会话 C-a C-a (other) 在当前会话和上一次会话之间跳转 C-a a (meta) Send the command character (C-a) to window. See escape command. C-a A (title) 设置当前窗口的名称name C-a b (break) Send a break to window. C-a B (pow_break) Reopen the terminal line and send a break. C-a c (screen) 创建一个新窗口并跳转到新窗口 C-a C (clear) 清空当前窗口的内容,类似于clear C-a d (detach) 剥离当前会话 C-a D D (pow_detach) 剥离并且退出当前终端logout C-a f (flow) Toggle flow on, off or auto. C-a F (fit) Resize the window to the current region size. C-a C-g (vbell) Toggles screen‘s visual bell mode. C-a h (hardcopy) Write a hardcopy of the current window to the file "hardcopy.n". C-a H (log) 开始/结束记录当前窗口内容到文件screenlog.n(n表示为num) C-a i (info) 显示当前窗口的信息 C-a k (kill) 关闭当前窗口 C-a l (redisplay) Fully refresh current window. C-a L (login) Toggle this windows login slot. Available only if screen is configured to update the utmp database. C-a m (lastmsg) Repeat the last message displayed in the message line. C-a M (monitor) Toggles monitoring of the current window. C-a n (next) 跳转到下一个窗口 C-a N (number) 显示当前窗口的num和名称name C-a p (prev) 跳转到上一个窗口 C-a q (xon) Send a control-q to the current window. C-a Q (only) Delete all regions but the current one. See also split, remove,focus. C-a r (wrap) Toggle the current window‘s line-wrap setting (turn the current window‘s automatic margins on and off). C-a s (xoff) Send a control-s to the current window. C-a S (split) 水平分割当前窗口 C-a t (time) 显示系统时间和负载 C-a v (version) Display the version and compilation date. C-a C-v (digraph) Enter digraph. C-a w (windows) 显示当前所有开启的窗口,*号表示当前窗口 C-a W (width) Toggle 80/132 columns. C-a x (lockscreen) 锁定终端,解锁需要密码 C-a X (remove) Kill the current region. See also split, only, focus. C-a z (suspend) Suspend screen. Your system must support BSD-style job-control. C-a Z (reset) Reset the virtual terminal to its "power-on" values. C-a . (dumptermcap) Write out a ".termcap" file. C-a C-\ (quit) Kill all windows and terminate screen. C-a : (colon) Enter command line mode. C-a [或者esc (copy) Enter copy/scrollback mode. C-a ] (paste .) Write the contents of the paste buffer to the stdin queue of the current window. C-a {或者} (history) Copy and paste a previous (command) line. C-a > (writebuf) Write paste buffer to a file. C-a < (readbuf) Reads the screen-exchange file into the paste buffer. C-a = (removebuf) Removes the file used by C-a < and C-a >. C-a , (license) Shows where screen comes from, where it went to and why you can use it. C-a _ (silence) Start/stop monitoring the current window for inactivity. C-a | (split -v) Split the current region vertically into two new ones. C-a * (displays) Show a listing of all currently attached displays.
本文出自 “rackie” 博客,请务必保留此出处http://rackie386.blog.51cto.com/11279229/1939442
以上是关于一天一命令-screen的主要内容,如果未能解决你的问题,请参考以下文章