screen 简单应用:
screen myprogram // 通过screen启动一个程序, 或者screen -L myprogram: turns on logging to ~/screenlog.0
ctr+a 然后再按一下 d // 使程序在后台运行,即detach
screen -ls // 列出在screen后台运行的程序,以及ID(例如4491.pts-2.localhost)
screen -r ID // 恢复运行程序到terminal,例如:screen -r 4491
exit //退出当前screen会话(同 ctrl+a 再按 k),有时候会打开很多screen,可以通过exit退出。
多窗口管理:
如果在某一个终端中运行了多次screen,即有嵌套的多层screen,则
ctrl+a 再按 w
可查看当前终端下的所有screen窗口,* 号 表示的是当前会话所在的窗口,然后ctrl+a 再按 0~9
即可切换到某个对应窗口。
介绍screen的很好的文章,just read it:
http://www.ibm.com/developerworks/cn/linux/l-cn-screen/
复杂点的应用如下:
When you use screen you need to detach with CTRL+A+D
before you exit ssh.
Alternatively, if you want to run a process directly with screen you can use
screen -dmSL [session name] [commands]
-d: starts a screen session and immediately detaches from it
-m: forces creating a new screen session
-S: lets you give the session a name
-L: turns on logging to ~/screenlog.0
example:
screen -dmSL myalias myscript.sh
You can then either:
resume later using screen -x myalias
or
check the log file less -r ~/screenlog.0
Screen Command Example 1: Execute a command (or shell-script), and detach the screen
$ screen unix-command-to-be-executed
$ screen ./unix-shell-script-to-be-executed
Once you’ve used the screen command, you can detach it from the terminal using any one of the following method.
Screen Detach Method 1: Detach the screen using CTRL+A d
When the command is executing, press CTRL+A
followed by d
to detach the screen.
Screen Detach Method 2: Detach the screen using -d
option
When the command is running in another terminal, type the command as following.
$ screen -d SCREENID
Screen Command Example 2: List all the running screen processes
You can list all the running screen processes using screen -ls
command.
For example:
On terminal 1 you did the following:
$ screen ./myscript.sh
From terminal 2 you can view the list of all screen processes. You can also detach it from terminal 2 as shown below.
$ screen -ls
There is a screen on:
4491.pts-2.localhost (Attached)
1 Socket in /var/run/screen/S-i5.
$ screen -d 4491.pts-2.localhost
[4491.pts-2.localhost detached.]
Screen Command Example 3: Attach the Screen when required
You can attach the screen at anytime by specifying the screen id as shown below. You can get the screen id from the “screen -ls” command output.
$ screen -r 4491.pts-2.FC547
我们先来理解下tmux的几个元素。tmux的主要元素分为三层:
tmux
命令创建一个Session。C-b+c
来创建。C-b+"
(水平分割,左右两个Pane) 或者 C-b+%
(垂直分割,上下两个Pane)。即:
session: 会话,一个服务器可以包含多个session
window: 窗口,一个session可以包含多个window
pane: 面板,一个window可以包含多个pane
快捷键一览:
tmux #开启tmux,新建一个session: t
tmux ls #显示已有tmux列表(C-b s)
tmux attach-session -t n #重新连接上第n个session, 即attach。或者: tmux a –t n
C-b c #创建一个新的窗口
C-b n #切换到下一个窗口
C-b p #切换到上一个窗口
C-b l #最后一个窗口,和上一个窗口的概念不一样哟,谁试谁知道
c-b w #通过上下键选择当前窗口中打开的会话
C-b n #直接跳到第n个窗口
C-b & #退出当前窗口(kill window,同时关闭所有小窗口)
C-b x #关闭当前光标处的小窗口或者如果只有一个窗口则关闭window
C-b d
临时断开会话,即dettach,类似screen的 ctrl+a+d (通过tmux ls查看Session号,例如0,然后tmux attach-session -t 0 重新attach)
C-b "
分割出来一个窗口
C-b %
分割出来一个窗口
C-b o
在小窗口中切换
C-b
(方向键)
C-b !
新建一个窗口,并将当前小窗口最大化
版权声明:本文为博主原创文章,未经博主允许不得转载。
原文地址:http://blog.csdn.net/gw569453350game/article/details/46530367