How to use Linux screen command

PHPz
Release: 2023-05-23 18:17:29
forward
4766 people have browsed it

1. Introduction to 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.

2. Usage examples

1. Install screen command

[root@s145]~# yum install -y screen
Installed:
screen.x86_64 0:4.1.0-0.27.20120314git3c2946.el7_9
Complete!

2. List all current sessions

[root@s145] ~# screen -ls
No Sockets found in /var/run/screen/S-root.

3. Create a new window

[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]~

#4. Exit the current window

  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.

How to use Linux screen command

How to use Linux screen command

5. Reconnect the window

  Use screen -r id or name to reconnect the session, The session status is required to be Detached before reconnecting the session.

How to use Linux screen command

How to use Linux screen command

How to use Linux screen command

6. Clear the dead status window

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.

How to use Linux screen command

7. Session locking and unlocking

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.

How to use Linux screen command

Enter ctl a x to lock the session. You need to enter the user password before you can unlock it.

How to use Linux screen command

8. Session sharing

How to use Linux screen command

How to use Linux screen command

9. Send commands to the screen window

[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

How to use Linux screen command

How to use Linux screen command

10. Screen split screen

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!

How to use Linux screen command

11. Practical example

Write a script that continuously outputs

[root@s145]~# cat test.sh 
#!/bin/bash
\
while true
do
  echo "输出`date +%F-%T`"
  sleep 10
done
Copy after login

Create a screen window

[root@s145]~# screen -S echotest

Execute the test.sh script

How to use Linux screen command

Make the echotest window offline in other sessions

[root@s145]~# screen -d echotest
[3405.echotest detached.]

How to use Linux screen command

##Reconnect session

How to use Linux screen command

3. Usage syntax and parameter description

1. Usage syntax

Usage: screen [-opts] [cmd [args]]

or :screen -r [host.tty]

2. Parameter description

##Parameter-4-6-a-A-[r-c file -d (-r) -dmS name -D (-r) -D-RR-e xy-f-h line -i-l-ls[match]-list-L-m-O-p windows-q-Q-r[session]-R-s shell-S sockname-t title-T term-U-v-wipe[match]-x-X3. Shortcut keys used in the Screen command
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.

    Ctrl a c: Create 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 automatically terminates and returns to the original shell state)
  • exit: Close the current window and switch to the next window ( When exiting the last window, the terminal automatically terminates and returns to the original shell state)
  • Ctrl a d: Exit the current terminal and return to the shell command state before loading the screen

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!

Related labels:
source:yisu.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!