Languages
[Edit]
EN

Linux screen - most useful commands with practical examples

3 points
Created by:
marc_so
894

In this article we are gonna have a look at most useful linux screen commands. Most of the time we just need a few screen commands to get the job done. Below we have a lot of them.

Why screen is useful?

If we run some program from command line and our terminal will shutdown (internet problem, lack of energy) we can't go back to that session. Especially if we run some important installation or download some large file via ssh from another server. It is important to have backup and run this with screen or nohup.

Installation of screen command

  • If we have debian or ubuntu:
apt-get install screen
  • If we have centos:
yum -y install screen

Most useful commands

  • screen create new session
screen -S my_first_screen_session
  • screen detach press keys (in this order - first ctrl, second a, third d)
ctrl + a + d
  • screen list all sessions
screen -ls

Usage example:

root@mail:/# screen -ls
There is a screen on:
        21173.my_first_screen_session   (03/27/2020 09:54:27 PM)        (Detached)
1 Socket in /run/screen/S-root.
  • screen connect to detached session (21173 - id of screen session - NOT ENTIRE NAME, just ID), we can get id by using screen -ls
screen -r 21173
  • screen kill session (21173 - id of screen session - NOT ENTIRE NAME, just ID)
screen -X -S 21173 quit

Usage example:

[detached from 21173.my_first_screen_session]
root@mail:/# screen -ls
There is a screen on:
        21173.my_first_screen_session   (03/27/2020 09:54:27 PM)        (Detached)
1 Socket in /run/screen/S-root.
root@mail:/# screen -X -S 21173 quit
root@mail:/# screen -ls
No Sockets found in /run/screen/S-root.

 

Donate to Dirask
Our content is created by volunteers - like Wikipedia. If you think, the things we do are good, donate us. Thanks!
Join to our subscribers to be up to date with content, news and offers.

Linux

Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂

Join