How To Install and Use Linux Screen, With Commands

Introduction

Linux screen provides users an option to open several separate terminal instances within a single terminal window manager. Screen also includes an enhanced command line, giving you extra features and functionality over a standard command line.

This tutorial will show you how to install and use Screen on a Linux system.

linux screen command tutorial

Prerequisites

  • A user account with sudo privileges
  • Access to a command line / terminal window (Ctrl+Alt+T/Ctrl+Alt+F2)

How to Install Screen on Linux

If you’re running a recent version of Linux, like Ubuntu 18.04 or CentOS 7, you probably already have Screen installed.

To verity if screen is installed,  check the version with the command:

screen –version
check screen version running on system

Installing Screen on CentOS

To install Screen on Red Hat / CentOS, enter the command:

yum install screen

Installing Screen on Debian or Ubuntu

To install screen on Debian/Ubuntu, enter the following:

sudo apt-get install screen

Commands to Start Screen

To launch Screen, enter the following at a command line:

screen

The tool will launch and give you a brief license agreement. Press the spacebar or Enter to continue to the Screen shell. The system will drop out to a command line that looks just like a regular terminal window.

screen shell on linux launching

Screen works using command keystrokes. These are usually Ctrl-a plus another key.

To display a list of available commands, enter the following:

ctrl–a
?
list of available commands for screen

When you launch the Screen application, it’s helpful to name the session. This helps you keep track of different instances.

To name a session with the –S option:

screen –S name_session

To exit Screen, use the following command:

exit

Note: Press and release the ctrl-a key combination, then hold the shift key and press the ? key.

Basic Commands in Screen to Manage Windows

When Screen is first launched, it creates one window inside of the Screen session. New windows can be created and switched using command keystrokes.

To open a new Screen window, use the following keystroke:

Ctrl-a
c

The original window is labeled 0 bash, unless you name it something different. Each new Screen window gets a number, up to 9.

Here is a list of useful commands for managing Screen windows:

Ctrl-a c – 

Create a new window

Ctrl-a “ 

List all open windows

Ctrl-a

0 – Switch to window #0 (or any other numbered window)

Ctrl-a A

Rename the current window

Ctrl-a S

Split the screen horizontally, with the current window on top

Ctrl-a |

– (pipe) Split the screen vertically, with the current window to the left

Ctrl-a tab

Switch between areas of the split screen (usually used along with

Ctrl-a 0

to run different windows side-by-side)

Ctrl-a Ctrl-a

Switch between current and previous windows

Ctrl-a n

– Switch to the next window

Ctrl-a p

– switch to the previous window

Ctrl-a Q

Quit all other windows except the current one

Ctrl-a x

Lock the current window

Ctrl-a H

– Create a running log of the session

Ctrl-a M

Monitor a window for output (Screen will flash a notification when that window has activity)

Ctrl-a _

– (underscore) Watch the window for the absence of output (such as when a file finishes downloading, or a compiler finishes)

Ctrl-a k

kill the Screen session (or you can type exit)

Detaching From Screen

You can leave a process working in Screen, and exit the interface. This is the equivalent of minimizing an application in a graphical operating system.

To detach from screen (and leave the window running in the background):

Ctrl-a d

Reattach to Screen

Screen helps preserve your work if your remote SSH connection drops.

To reconnect to the server, use the screen –ls command.

If you have multiple sessions running, you may need to find the screen session ID

To list different Screen sessions from a standard command line with:

screen –ls

This only lists sessions that are created with the screen command. Windows inside a session won’t be listed. If you have multiple different Screen instances running, each will have a different session ID.

This command lists all the Screen sessions that kept running after you disconnected.

You can then reattach to that Screen using the screen –r [sessionID]command.

To reattach to a running Screen instance:

screen –r [sessionID]

Note: If you only have one Screen instance, you don’t need to enter the session ID. If you have more than one, you’ll need to specify which session ID you want to reconnect to.

Customizing Screen

Like many Linux applications, Screen uses a customizable configuration file. Find the system-wide configuration file at /etc/screenrc. The user’s configuration file is located at ~/.screenrc.

Open the file for editing:

sudo nano /etc/screenrc
screen configuration file to edit

Most of the settings can be toggled by removing the comment (#) sign at the beginning of the line.

Conclusion

This tutorial showed you how to install Linux screen as well as the basic commands for using it.

Once you have mastered using the screen interface, you can navigate through multiple terminals, multitask and work more efficiently.

原创文章,作者:3628473679,如若转载,请注明出处:https://blog.ytso.com/224068.html

(0)
上一篇 2022年1月7日
下一篇 2022年1月7日

相关推荐

发表回复

登录后才能评论