Home > Article > Operation and Maintenance > How to use Linux screen command
Screen is a full-screen window manager that allows multiple processes (usually interactive shells) to be multiplexed between physical terminals. Each virtual terminal has DEC VT100 terminal and ANSI X3 control functions. ISO 6429 (64) and ISO 2022 standards (e.g. insertion/deletion of lines and support for multiple character sets). Users can take advantage of each virtual terminal's scrollback history buffer and copy-paste mechanism to move text areas between windows. When screen is called, it creates a window containing the shell (or the specified command) and then gets out of your way so that you can use the program normally. You can then at any time create new (full-screen) windows containing other programs (including more shells), close the current window, view the list of active windows, turn the output log on and off, copy text between windows, view the scroll history, Switch between windows, etc. All windows run their programs completely independently. Programs continue to run when the window is not currently visible, and even when the entire screen session is detached from the user's terminal.
[root@s145]~# yum install -y screen
Installed:
screen.x86_64 0:4.1.0-0.27.20120314git3c2946.el7_9
Complete!
[root@s145] ~# screen -ls
No Sockets found in /var/run/screen/S-root.
[root @s145]~# screen -S test
…
[root@s145]~# screen -ls
There is a screen on:
2877.test (Attached)
1 Socket in /var/run/screen/S-root.
[root@s145]~
You can use ctrl a , and then enter d to exit the current window. You can also use screen -d to exit the current window. If you want to end only the window use exit.
Use screen -r id or name to reconnect the session, The session status is required to be Detached before reconnecting the session.
When the session window is ended After that, the process status becomes dead and unable to connect. At this time, you can use the command "screen -wipe" to clear the session window.
Enter ctl a s to lock the session. After locking, the screen will not respond to any input. After entering ctl a q, it will unlock. Although When the screen is locked, it will not respond but will accept the commands entered. After unlocking, all commands will be executed. Do not enter dangerous commands, so it is recommended to use ctl a x to lock.
Enter ctl a x to lock the session. You need to enter the user password before you can unlock it.
[root@s145]~# date && screen -S test -X screen ls > /tmp/1.txt
Tue Jan 11 17:12:24 CST 2022
[root@ s145]~# screen -S test -X screen sh /root/test.sh
It’s normal to use shortcut keys to split the screen, but you can’t enter commands when the screen is split. If you know, you can leave a message and tell me the reason. Please give me some advice. Thank you!
Write a script that continuously outputs
[root@s145]~# cat test.sh #!/bin/bash \ while true do echo "输出`date +%F-%T`" sleep 10 done
Create a screen window
[root@s145]~# screen -S echotest
Execute the test.sh script
Make the echotest window offline in other sessions
[root@s145]~# screen -d echotest
[3405.echotest detached.]
Usage: screen [-opts] [cmd [args]]2. Parameter descriptionor :screen -r [host.tty]
Parameter description | |
---|---|
Resolve hostnames to IPv4 addresses only. | |
Resolve hostnames to IPv6 addresses only. | |
Forces all features into per-window termcap. | |
r] | |
Read configuration file Rather than’. screenrc’. | |
Detach a screen running elsewhere (and reattach here). | |
Started as daemon: screen session in detached mode. | |
Detach and log off the remote (and reconnect here). | |
Do whatever is needed to get a screen session. | |
Change the command characters. | |
Flow control on, -fn=off, -fa=auto. | |
Sets the size of the rollback history buffer. | |
When flow control is on, interrupt output is faster. | |
Login mode is turned on (update /var/run/utmp), -ln=off. | |
Does nothing, just lists our SockDir [about possible matches], same as -list | |
Does nothing, just lists our SockDir [about possible matches]. | |
Turn on output logging. | |
Ignore the $STY variable and create a new screen session. | |
Choose the best output instead of an exact vt100 simulation. | |
Preselects the named window if it exists. | |
Quiet startup. If unsuccessful, exit with a non-zero return code. The | |
command will send a response to the standard output of the query process. | |
Reconnect to the detached screen process. | |
Reconnect if possible, otherwise start a new session. | |
The shell to execute, not $shell. | |
Name this session. sockname instead of |
|
Set the title. (window name). | |
Use term as $term for windows, not "screen". | |
tells the screen to use UTF-8 encoding. | |
prints "Screen version 4.01.00devel (GNU) May 2, 2006". | |
Does nothing, just clears SockDir[possible matches]. | |
Connect to an undetached screen. (Multiple display mode). | |
Executed as a screen command in the specified session. |
The above is the detailed content of How to use Linux screen command. For more information, please follow other related articles on the PHP Chinese website!