What is the screen command and how to use it?

screen is a terminal multiplexer program used to manage multiple windows and sessions within a Unix or Linux terminal. It provides users with the ability to run multiple processes in the same terminal window, continue sessions if disconnected, control processes running on a remote server, and run processes in the background, among other advantages.

When using screen, you can create and switch between multiple “screens” within the same terminal window. This allows you to manage several tasks simultaneously. Additionally, screen sessions can be saved and later restored.

screen is usually pre-installed on many Linux distributions. However, if it’s not installed on your system, you can easily install it using the package manager for your specific distribution. Here are example commands for popular Linux distributions:

Debian/Ubuntu-based systems (using apt):

sudo apt update
sudo apt install screen

Red Hat/Fedora-based systems (using dnf or yum):

sudo dnf install screen # For Fedora 22 and later versions
# or
sudo yum install screen # For Fedora 21 and earlier versions

CentOS-based systems (using yum):

sudo yum install screen

openSUSE-based systems (using zypper):

sudo zypper install screen

Arch Linux-based systems (using pacman):

sudo pacman -S screen

By using the above commands, you can install screen on your system. Once the installation is complete, you can start a screen session by using the screen command in a terminal window.

Here are some basic commands for using screen:

  • Create a Screen:
    screen
  • List Screens:
    screen -ls
  • Switch to the Next Screen:
    Ctrl-a n
  • Switch to the Previous Screen:
    Ctrl-a p
  • Create a New Screen:
    Ctrl-a c
  • Switch Between Screens:
    Ctrl-a " (double quote)
  • Close a Screen:
    exit
  • Save a screen Session:
    screen -S session_name -X screen
  • Restore a screen Session:
    screen -r session_name

These commands cover the basic usage of screen. You can refer to the comprehensive documentation of screen by using the man screen command for more details and advanced features.

Basic screen Commands:

  • Attach to a Specific screen Session:
    screen -r session_name
  • Create a New Window:
    Ctrl-a c
  • Switch to the Next Window:
    Ctrl-a n
  • Switch to the Previous Window:
    Ctrl-a p
  • List Open Windows:
    Ctrl-a w
  • Detach from the Current screen Session (Leave it Running in the Background):
    Ctrl-a d
  • Terminate the Current screen Session:
    exit

Advanced screen Commands:

  • Rename the Current screen Session:
    Ctrl-a A
  • Scrollback Mode (Enter Copy Mode):
    Ctrl-a [
  • Toggle Logging of the screen Session:
    Ctrl-a H
  • Lock the Terminal:
    Ctrl-a x
  • Split the Terminal Horizontally:
    Ctrl-a S
  • Split the Terminal Vertically:
    Ctrl-a |
  • Toggle Focus Between Split Regions:
    Ctrl-a Tab
  • Close the Region that the Cursor is In:
    Ctrl-a X

Saving and Restoring screen Sessions:

  • Save the screen Session:
    screen -S session_name -X screen
  • Restore a Saved screen Session:
    screen -r session_name

This cheat sheet covers basic and some advanced commands for using screen. Adjustments might be needed based on your specific use case and screen configuration. For more detailed information, you can refer to the man screen command.

 

0 Shares:
Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

You May Also Like
DNS Record Types Explained
Read More

DNS Record Types Explained

DNS (Domain Name System) is a hierarchical and distributed naming system for computers, services, or other resources connected…
Read More

Nagios Architecture

Nagios is a network and system monitoring application designed to continuously monitor the status of networks, servers, devices,…