Home > Article > System Tutorial > screen command usage
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 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 screenscreen
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)
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
Ubuntu/Debian
apt-get -y install screenHow 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
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
Replace "name" with a name that is meaningful to your session.
Detach from screen sessionTo 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 sessionIf you detach from a session, or for some reason your connection is interrupted, you can reconnect using the following command:
screen -r
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.
In our example, we have three active screen sessions. So if you want to restore the "session2" session you can do:
screen -r 7934
Or use screen name.
screen -r -S session2Abort 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]]
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!