Languages
[Edit]
EN

Linux screen - most useful commands with practical examples

3 points
Created by:
Kate_C
2895

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.

 

Hey 👋
Would you like to know what we do?
  • Dirask is a friendly IT community for learners, professionals and hobbyists to share their knowledge and help each other in extraordinary easy way.
  • We welcome everyone,
    no matter what the experience,
    no matter how basic the question is,
    this community will help you.