Home > System Tutorial > LINUX > body text

screen command usage

王林
Release: 2023-12-29 08:07:38
forward
752 people have browsed it
Introduction screen is a very useful command that provides the ability to use multiple shell windows (sessions) from a single SSH session. When the session is detached or the network is interrupted, processes started in the screen session will still run, and you can reconnect to the screen session at any time

screen 命令使用

screen is a very useful command that provides the ability to use multiple shell windows (sessions) from a single SSH session. When the session is detached or the network is interrupted, processes started in the screen session will still run, and you can reconnect to the screen session at any time. This is also convenient if you want to run a persistent process or connect to a shell session from multiple locations.

In this article, we will show you the basics of installing and using screen on Linux.

How to install screen
screen
Copy after login

Already pre-installed on some popular distributions. You can check if it is installed on your server using the command below.

screen -v
Screen version 4.00.03 (FAU)
Copy after login

If you don't have screen in Linux yet, you can easily install it using the package manager provided by your system.

CentOS/RedHat/Fedora

yum -y install screen
Copy after login

Ubuntu/Debian

apt-get -y install screen
Copy after login
How to start a screen session

You can start it by typing screen at the command line, and a screen session will start that looks the same as the command line prompt.

screen
Copy after login

It is a good practice to start a screen session with a descriptive name so that you can easily remember what processes are running in the session. To create a new session using the session name, run the following command:

screen -S name
Copy after login

Replace "name" with a name that is meaningful to your session.

Detach from screen session

To detach from the current screen session, you can press Ctrl-A and d. All screen sessions will still be active and you can reconnect at any time later.

Reconnect to screen session

If you detach from a session, or for some reason your connection is interrupted, you can reconnect using the following command:

screen -r
Copy after login

If you have multiple screen sessions, you can list them with the ls parameter.

screen -ls

There are screens on:
7880.session    (Detached)
7934.session2   (Detached)
7907.session1   (Detached)
3 Sockets in /var/run/screen/S-root.
Copy after login

In our example, we have three active screen sessions. So if you want to restore the "session2" session you can do:

screen -r 7934
Copy after login

Or use screen name.

screen -r -S session2
Copy after login
Abort screen session

There are several ways to terminate a screen session. You can press Ctrl d or use the exit command from the command line.

To see all the useful functions of the screen command, you can view the man manual of screen.

man screen

NAME
screen - screen manager with VT100/ANSI terminal emulation

SYNOPSIS
screen [ -options ] [ cmd [ args ] ]
screen -r [[pid.]tty[.host]]
screen -r sessionowner/[[pid.]tty[.host]]
Copy after login

By the way, if you like this article, please share it with your friends on social networks or leave a comment in the comment section. Thanks.


The above is the detailed content of screen command usage. For more information, please follow other related articles on the PHP Chinese website!

source:linuxprobe.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