Linux Screen Command Examples

Linux Screen Tutorial

 

In this Linux Screen tutorial you will learn how to install screen on CentOS, Ubuntu, and how to use Linux screen command with examples.

Official GNU Screen man pages. Or:

#man screen

 

What is GNU Screen

Screen command in Linux or GNU Screen main purpose to multiplex single SSH terminal.

Screen is very useful program for most cases. I am always using it when SSH connection may interpreted,

  • Keep active multiple SSH terminal sessions
  • Keep terminal sessions alive after SSH disconnection
  • Reconnect to disconnected active terminals
  • Switch between terminals

 

Install Linux Screen

 

To install  Screen utility package in your system:

Install Screen on Ubuntu / Debian

$ sudo apt-get update
$ sudo apt-get install screen

Install Screen CentOS / RedHat

# yum install screen

 

To install on CentOS 8 folow guide: How To Install Linux Screen on CentOS 8

 

 

Linux Screen command examples

 

Starting Screen:

$ screen

Creating new session

To create new terminal session press “Ctrl + a” following “c” keys combination.

 

Switch to next session

If you have more than session you can switch between windows using “Ctrl + a” and “n” combination.

 

Switch to previous session

Switch to previous screen: “Ctrl + a” and “p

 

Detach from Linux Screen

Ctrl + a” and “d” will detach from Linux screen session, but program running in the session will still run after detaching. And you will able reattach and resume session at any time.

 

Reattach and Resume Screen Session

To attach and resume detached session run

$ screen -r

or

$ screen -r ID

Where ID is session ID. In case if you have more than 1 detached screen sessions, you must enter session ID also.

 

List Screens or Find out Screen Session ID

To find out screen session ID’s and list screens you have to use screen -ls or:

$ screen -list

screen -ls

As shown on screenshot I have 2 screens with ID’s 1747 and 1693.  To reattach, for example screen with ID 1747 I should type:

$ screen -r 1747

 

How to use Linux Screen

 

In next video animation you see basic usage of Screen program:

  1. Starting GNU Screen utility
  2. In new window starting htop utility
  3. Creating new Screen window: “Ctrl + a” following “c
  4. In new window starting top utility
  5. Switching to next window: “Ctrl + a” and “n
  6. Detaching from Linux Screen: “Ctrl + a” and “d
  7. Listing Screens: screen -ls
  8. Reattaching and resume Screen session

 


 

If you like what you are reading, please:

Buy me a coffeeBuy me a coffee

arstech

Leave a Reply