How to use Linux screen command

09-12-2023

I. Introduction to the screen command Screen is a full-screen window manager, which allows multiple processes (usually interactive shell) to multiplex between physical terminals. Each virtual terminal has the control functions of DEC VT100 terminal and ANSI X3. ISO 6429 (64) and ISO 2022 standards (e.g. insertion/deletion of lines and support for multiple character sets)。 Users can use the rollback history buffer and copy-paste mechanism of each virtual terminal to realize the function of moving text areas between windows. When screen is called, it will create a window containing a shell (or a specified command) and then avoid your way so that you can use the program normally. Then, you can create a new (full-screen) window containing other programs (including more shell) at any time, close the current window, view the list of active windows, turn on and off the output log, copy text between windows, view the scrolling history, switch between windows, and so on. All windows run their programs completely independently. When the window is currently invisible, the program continues to run even when the entire screen session is separated from the user terminal.

Second, the use of example 1, install the screen command


5. Reconnect the window     Reconnect the session with screen -r id or name, and the status of the session is required to be Detached before reconnecting the session.


6. Clear the dead status window When the session window is ended, the process status becomes dead and cannot be connected. At this time, you can use the command "screen -wipe" to clear the session window.


7. Session Locking and Unlocking Enter ctl+a s to lock the session. After locking, the screen will not respond to anything entered. After entering ctl+a q, it will unlock. Although there is no response when the screen is locked, it will accept the input commands. After unlocking, it will all 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, and you need to enter the user password before you can unlock it.


8. Session sharing 


9. Send a command to the screen window


10, the screen split screen using shortcut keys is normal, but the split screen can not input commands, if you know the brother can leave a message to tell the reason, ask for advice, thank you!


11. Practice Example Write a script with continuous output.

Take the echotest window offline in other sessions.

Reconnect session


Iii. usage grammar and parameter description 1. usage grammar: screen [-opts] [cmd [args]] or: screen -r [host.tty]

2. Parameter Description Parameter Description -4 Only the host name is resolved into an IPv4 address. -6 Resolves host names to IPv6 addresses only. -a forces all functions into the termcap of each window. -A-[rr]-c file reads the configuration file instead of ’ . screenrc’ . -d(-r) Detach the screen running elsewhere (and reconnect it here). -dmS name starts as a daemon: screen session in detached mode. -D(-r) Detach and log off the remote (and reconnect here). -D-RR does anything necessary to get a screen conversation. -e xy changes the command character. -f flow control is on, -fn= off, -fa= automatic. The -h line sets the size of the rollback history buffer. When -i flow control is on, the interrupt output is faster. -l login mode is on (update /var/run/utmp), -ln=off. -ls[match] does nothing, only lists our socks [about possible matches], and does nothing with -list-list, only lists our socks [about possible matches]. -L Turn on output logging. -m Ignore the $STY variable and create a new screen session. -O Choose the best output instead of an accurate vt100 simulation. -p windows If the named window exists, preselect it. -q, start quietly. If unsuccessful, exit with a non-zero return code. The -Q command will send a response to the standard output of the query process. -r[session] reconnects to the separated screen process. -R Reconnect if possible, otherwise start a new session. -s shell the shell to execute, not the $shell. -S sockname names this session as. Sockname instead of. -t title sets the title. (window name). -t $term uses the term as the $ TERM of windows, not the screen. -U tells the screen to use UTF-8 encoding. -v Print screen version 4.01.00devel(GNU)2006) May 2, 2006. -wipe[match] Do nothing, just clean up SockDir[ possible matches]. -x is connected to the non-separated screen. (Multi-display mode). -X is executed as an on-screen command in the specified session. 3. the shortcut key Ctrl+a c used in the Screen command: create a window.

Ctrl+a w: window list

Ctrl+a n: next window

Ctrl+a p: previous window

Ctrl+a 0-9: Switch between the 0th window and the 9th window.

Ctrl+a K (uppercase): Close the current window and switch to the next window (when exiting the last window, the terminal will automatically terminate and return to the original shell state).

Exit: Close the current window and switch to the next window (when exiting the last window, the terminal will automatically terminate and return to the original shell state).

Ctrl+a d: Exit the current terminal and return to the shell command state before loading screen.

Copyright Description:No reproduction without permission。

Knowledge sharing community for developers。

Let more developers benefit from it。

Help developers share knowledge through the Internet。

Follow us