Table of Contents
1. Introduction to screen command
2. Usage examples
1. Install screen command
2. List all current sessions
3. Create a new window
#4. Exit the current window
5. Reconnect the window
6. Clear the dead status window
7. Session locking and unlocking
8. Session sharing
9. Send commands to the screen window
10. Screen split screen
11. Practical example

How to use Linux screen command

May 23, 2023 pm 06:17 PM
linux screen

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!

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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
1 months ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

What is Linux actually good for? What is Linux actually good for? Apr 12, 2025 am 12:20 AM

Linux is suitable for servers, development environments, and embedded systems. 1. As a server operating system, Linux is stable and efficient, and is often used to deploy high-concurrency applications. 2. As a development environment, Linux provides efficient command line tools and package management systems to improve development efficiency. 3. In embedded systems, Linux is lightweight and customizable, suitable for environments with limited resources.

How to start apache How to start apache Apr 13, 2025 pm 01:06 PM

The steps to start Apache are as follows: Install Apache (command: sudo apt-get install apache2 or download it from the official website) Start Apache (Linux: sudo systemctl start apache2; Windows: Right-click the "Apache2.4" service and select "Start") Check whether it has been started (Linux: sudo systemctl status apache2; Windows: Check the status of the "Apache2.4" service in the service manager) Enable boot automatically (optional, Linux: sudo systemctl

What to do if the apache80 port is occupied What to do if the apache80 port is occupied Apr 13, 2025 pm 01:24 PM

When the Apache 80 port is occupied, the solution is as follows: find out the process that occupies the port and close it. Check the firewall settings to make sure Apache is not blocked. If the above method does not work, please reconfigure Apache to use a different port. Restart the Apache service.

How to monitor Nginx SSL performance on Debian How to monitor Nginx SSL performance on Debian Apr 12, 2025 pm 10:18 PM

This article describes how to effectively monitor the SSL performance of Nginx servers on Debian systems. We will use NginxExporter to export Nginx status data to Prometheus and then visually display it through Grafana. Step 1: Configuring Nginx First, we need to enable the stub_status module in the Nginx configuration file to obtain the status information of Nginx. Add the following snippet in your Nginx configuration file (usually located in /etc/nginx/nginx.conf or its include file): location/nginx_status{stub_status

How to start monitoring of oracle How to start monitoring of oracle Apr 12, 2025 am 06:00 AM

The steps to start an Oracle listener are as follows: Check the listener status (using the lsnrctl status command) For Windows, start the "TNS Listener" service in Oracle Services Manager For Linux and Unix, use the lsnrctl start command to start the listener run the lsnrctl status command to verify that the listener is started

How to set up a recycling bin in Debian system How to set up a recycling bin in Debian system Apr 12, 2025 pm 10:51 PM

This article introduces two methods of configuring a recycling bin in a Debian system: a graphical interface and a command line. Method 1: Use the Nautilus graphical interface to open the file manager: Find and start the Nautilus file manager (usually called "File") in the desktop or application menu. Find the Recycle Bin: Look for the Recycle Bin folder in the left navigation bar. If it is not found, try clicking "Other Location" or "Computer" to search. Configure Recycle Bin properties: Right-click "Recycle Bin" and select "Properties". In the Properties window, you can adjust the following settings: Maximum Size: Limit the disk space available in the Recycle Bin. Retention time: Set the preservation before the file is automatically deleted in the recycling bin

How to restart the apache server How to restart the apache server Apr 13, 2025 pm 01:12 PM

To restart the Apache server, follow these steps: Linux/macOS: Run sudo systemctl restart apache2. Windows: Run net stop Apache2.4 and then net start Apache2.4. Run netstat -a | findstr 80 to check the server status.

How to optimize the performance of debian readdir How to optimize the performance of debian readdir Apr 13, 2025 am 08:48 AM

In Debian systems, readdir system calls are used to read directory contents. If its performance is not good, try the following optimization strategy: Simplify the number of directory files: Split large directories into multiple small directories as much as possible, reducing the number of items processed per readdir call. Enable directory content caching: build a cache mechanism, update the cache regularly or when directory content changes, and reduce frequent calls to readdir. Memory caches (such as Memcached or Redis) or local caches (such as files or databases) can be considered. Adopt efficient data structure: If you implement directory traversal by yourself, select more efficient data structures (such as hash tables instead of linear search) to store and access directory information

See all articles