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 屏幕
$ 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 命令。
$ 屏幕 ./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.]
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
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.
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.