Screen命令提供了将长时间运行的进程(或程序或shell脚本)从会话中分离出来,然后在以后附加它的功能。
When the session is detached, the process that was originally started from the 屏幕 is still running and managed 通过 the 屏幕. You can then re-attach the session at a later time, and your terminals are still there, the way you left them.
In this article, let us review the how to manage the virtual terminal sessions using 屏幕 command with examples.
Screen Command Example 1: Execute a command (or shell-script), and detach the 屏幕
通常你’ll从命令中执行如下所示的命令或shell脚本。
$ Unix命令-to-be-executed $ ./unix-shell-script-to-be-executed
Instead, use the 屏幕 command as shown below.
$ 屏幕 Unix命令-to-be-executed $ 屏幕 ./unix-shell-script-to-be-executed
一旦您’ve used the 屏幕 command, you can detach it from the terminal using any 上 e of the following method.
Screen Detach Method 1: Detach the 屏幕 using CTRL + A d
执行命令时,按 CTRL + A 其次是 d to detach the 屏幕.
Screen Detach Method 2: Detach the 屏幕 using -d option
当该命令在另一个终端上运行时,请按如下所示键入命令。
$ 屏幕 -d SCREENID
Screen Command Example 2: List all the running 屏幕 processes
You can list all the running 屏幕 processes using 屏幕 -ls 命令。
例如:
在1号航站楼上,您执行了以下操作:
$ 屏幕 ./myscript.sh
From terminal 2 you can view the list of all 屏幕 processes. You can also detach it from terminal 2 as shown below.
$ 屏幕 -ls There is a 屏幕 上 : 4491.pts-2.FC547 (Attached) 1 Socket in /var/run/screen/S-sathiya. $ 屏幕 -d 4491.pts-2.FC547 [4491.pts-2.FC547 detached.]
屏幕命令示例3:在需要时附加屏幕
You can attach the 屏幕 at anytime 通过 specifying the 屏幕 id as shown below. You can get the 屏幕 id from the “screen -ls” command output.
$ 屏幕 -r 4491.pts-2.FC547
屏幕命令使用场景1
When you have access to 上 ly 上 e terminal, you can use 屏幕 command to multiplex the single terminal into multiple, and execute several commands. You might also find it very useful to combine the usage of 屏幕 command along with the usage of SSH ControlMaster.
屏幕命令使用场景2
When you are working in a team environment, you might walk over to your colleagues desk and get few things clarified. At that time, if needed, you can even start some process from their machine using 屏幕 command and detach it when you are done. Later when you get back to your desk, you can login and attach the 屏幕 back to your terminal.
如果您喜欢这篇文章,您可能还会喜欢..
![]() |
![]() |
![]() |
![]() |
为什么不使用tmux呢?
http://tmux.sourceforge.net/
乍一看似乎很克隆,但一段时间后肯定会更好…