国产av日韩一区二区三区精品,成人性爱视频在线观看,国产,欧美,日韩,一区,www.成色av久久成人,2222eeee成人天堂

Home System Tutorial LINUX 20 Screen Command Examples to Manage Linux Terminals

20 Screen Command Examples to Manage Linux Terminals

Jun 24, 2025 am 10:19 AM

Brief: In this guide, we will discuss some useful examples of the screen command. By the end of this guide, users will be able to work with multiple shell sessions using a single Linux terminal window.

As Linux users, we often need to work on long-running tasks, such as – downloading or copying large files, executing time-consuming database queries, and so on. Sometimes these important tasks get terminated abruptly due to a session timeout.

To mitigate such scenarios, we can use the screen command, which is a full-screen software program that can be used to multiplexes a physical console between several processes (typically interactive shells). It offers a user to open several separate terminal instances inside a single terminal window manager.

The screen application is very useful if you are dealing with multiple programs from a command-line interface and for separating programs from the terminal shell. It also allows you to share your sessions with others users and detach/attach terminal sessions.

In this guide, we will discuss how to install, configure, and use the screen command on a Linux system. Throughout this guide, we will understand the usage and benefits of the screen command using practical examples.

Table of Contents

So let’s get started.

Install Screen Command in Linux

On my Ubuntu Server Edition, the screen command has been installed by default. But, Linux Mint does not have a screen installed by default, so I need to install it first using the apt-get command before using it.

Please follow your distribution installation procedure to install the screen.

$ sudo apt-get install screen      [On <strong>Debian, Ubuntu and Mint</strong>]
$ sudo yum install screen          [On <strong>RHEL/CentOS/Fedora</strong> and <strong>Rocky Linux/AlmaLinux</strong>]
$ sudo emerge -a sys-apps/screen   [On <strong>Gentoo Linux</strong>]
$ sudo apk add screen              [On <strong>Alpine Linux</strong>]
$ sudo pacman -S screen            [On <strong>Arch Linux</strong>]
$ sudo zypper install screen       [On <strong>OpenSUSE</strong>]    

Now, let’s verify that the command has been installed successfully:

$ screen --version

<strong>Screen version 4.8.00 (GNU) 05-Feb-20</strong>

Actually, the screen is a very good terminal multiplexer program in Linux which is hidden inside hundreds of Linux commands.

Let’s start to see the usage of the screen command in Linux with the following examples.

Screen Command Syntax

The syntax of the screen command is as follows

$ screen [OPTIONS] [ CMD [ ARGS ] ]

In the above syntax, we can see that all the parameters are options and they are represented by the square brackets ([]).

1. Start Screen for the First Time

Just type the screen at the command prompt. Then the screen will show an interface exactly as the command prompt.

$ screen

20 Screen Command Examples to Manage Linux Terminals

2. Show Screen Parameter

When you enter the screen, you can do all your work as you are in the normal command-line environment. But since the screen is an application, so it has commands or parameters.

Type “Ctrl-A” and “?” without quotes. Then you will see all commands or parameters on the screen.

20 Screen Command Examples to Manage Linux Terminals

To get out of the help screen, you can press the “space-bar” button or “Enter“. (Please note that all shortcuts which use “Ctrl-A” are done without quotes).

3. How to List All Open Windows

In the previous example, we started a new shell session using the screen command. Now let’s use the ctrl-a " key combination to list all open windows of the current screen session:

20 Screen Command Examples to Manage Linux Terminals

In the above output, we can see the number and name of the window. The first column represents the window number and it starts from zero.

The next column represents the name of the window and its default format is <user>@<hostname>:<working-directory></working-directory></hostname></user>.

4. How to Terminate Screen Window Session

We can terminate the active window session using the ctrl-a k key combinations. It is important to note that, this action will interrupt the command execution from the current virtual window.

20 Screen Command Examples to Manage Linux Terminals

In the above output, we can see that the screen command is waiting for the user’s confirmation. It shows the warning message in the left bottom corner.

Just like other Linux commands, we can use 'y' to continue or 'n' to abort the operation.

5. How to Start a Screen Session with Name

The screen command allows us to create a session with a user-defined name, which comes in handy when there are multiple sessions available.

So, let’s use the -S option of the command to create a named session:

$ screen -S demo-screen

In the above command, the demo-screen is the name of the session.

6. Detach the Terminal Session with Screen

One of the advantages of a screen that is you can detach it. Then, you can restore it without losing anything you have done on the screen. Here’s the sample scenario:

You are in the middle of SSH on your server. Let’s say that you are downloading a?400MB patch for your system using the wget command.

The download process is estimated to take 2 hours long. If you disconnect the SSH session, or suddenly the connection is lost by accident, then the download process will stop. You have to start from the beginning again. To avoid that, we can use a screen and detach it.

Take a look at this command. First, you have to enter the screen.

$ screen

Then you can do the download process. For example on my Linux Mint, I am upgrading my dpkg package using the apt command.

$ sudo apt install dpkg
Sample Output
Reading package lists... Done
Building dependency tree      
Reading state information... Done
The following packages will be upgraded:
  dpkg
1 upgraded, 0 newly installed, 0 to remove and 1146 not upgraded.
Need to get 2,583 kB of archives.
After this operation, 127 kB of additional disk space will be used.
Get:1 http://debian.linuxmint.com/latest/ 
testing/main dpkg i386 1.16.10 [2,583 kB]
47% [1 dpkg 1,625 kB/2,583 kB 47%]     14,7 kB/s

While downloading in progress, you can press “Ctrl-A” and “d“. You will not see anything when you press those buttons. The output will be like this:

[detached from 5561.pts-0.mint]
pungki@mint ~ $

7. Re-attach the Terminal Session with Screen

After you detach the screen, let’s say you are disconnecting your SSH session and going home. In your home, you start to SSH again to your server and you want to see the progress of your download process. To do that, you need to restore the screen. You can run this command:

pungki@mint ~ $ screen -r

And you will see that the process you left is still running.

When you have more than 1 screen session, you need to type the screen session ID. Use screen -ls to see how many screens are available.

pungki@mint ~ $ screen -ls
Sample Output
pungki@mint ~ $ screen -ls
There are screens on:
        <strong>7849.pts-0.mint</strong> (10/06/2021 01:50:45 PM)        (Detached)
        5561.pts-0.mint (10/06/2021 11:12:05 AM)        (Detached)
2 Sockets in /var/run/screen/S-pungki

If you want to restore screen 7849.pts-0.mint, then type this command.

pungki@mint ~ $ screen -r 7849

8. Using Multiple Screen Terminal Windows

When you need more than 1 screen to do your job, is it possible? Yes, it is. You can run multiple screen windows at the same time. There are 2 (two) ways to do it.

First, you can detach the first screen and run another screen on the real terminal. Second, you do a nested screen as shown.

To create new windows, use the ctrl-a c key combination two times to create two new windows. Next, let’s use the ctrl-a " key combination to list all active windows:

20 Screen Command Examples to Manage Linux Terminals

In the above output, we can see that now there are three windows.

9. How to Rename a Screen Window

In the previous example, we created two new windows. However, their default names are not providing any details about them. In such cases, we can assign some meaningful names to them.

We can use the ctrl-a A key combination to rename the current window session. This key combination prompts a user to set a window title:

20 Screen Command Examples to Manage Linux Terminals

10. Switching Between Screen Terminal Windows

In the previous example, we created multiple windows. Now let’s see how to switch between them.

First, let’s list all active windows using the ctrl-a " key combination. Next, use the up or down arrow key to select the appropriate window. Finally, press the enter key to switch to the selected window.

20 Screen Command Examples to Manage Linux Terminals

In this example, we have selected the window with the title – db-query.

11. How to Move to the Next Screen Window

We can use the ctrl-a n key combination to move to the next windows. Let’s understand this with an example.

First, switch to the first window and verify it using the ctrl-a " key combination:

20 Screen Command Examples to Manage Linux Terminals

Now, let’s press the ctrl-a n key combination two times to go to the third window and use the ctrl-a " key combination to verify the same.

20 Screen Command Examples to Manage Linux Terminals

In the above output, we can see now we are on the third window.

12. How to Move to the Previous Screen Window

In a similar way, we can use the ctrl-a p combination to switch to the previous window.

Currently, we are on the third window. So, let’s use the ctrl-a p key combination two times and verify that we are on the first window again:

20 Screen Command Examples to Manage Linux Terminals

In the above output, we can see that now we came back to the first window.

13. How to Switch Between Current and Previous Window

Sometimes, we just want to switch between two windows. In such cases, we can use the ctrl-a ctrl-a key combination.

To understand this, first switch to the first window:

20 Screen Command Examples to Manage Linux Terminals

Next, switch to the last window:

20 Screen Command Examples to Manage Linux Terminals

Finally, use the ctrl-a ctrl-a key combination to jump to the first window again.

14. How to Jump to a Particular Screen Window

In the previous examples, we saw various ways to switch between windows. However, sometimes we want to jump to a particular window. In such scenarios, we can use the window numbers.

First, let’s use the ctrl-a " key combination to find the window number:

20 Screen Command Examples to Manage Linux Terminals

In the above output, the first column represents the window number. It is important to note that, the screen command starts numbering from zero.

Now, let’s use the ctrl-a 2 key combination to jump to the third window and verify that we are in the correct window:

20 Screen Command Examples to Manage Linux Terminals

15. How to Split a Screen Window Horizontally

Just like normal terminals, we can also split the screen window. We can use the ctrl-a S key combination to split the window horizontally.

20 Screen Command Examples to Manage Linux Terminals

Now, we can use the ctrl-a tab key combination to jump between the regions.

Lastly, we can use the ctrl-a X key combination to remove the current region. It is important to note that here we have to use an uppercase X character.

16. How to Split a Screen Window Vertically

Similarly, we can use the ctrl-a | key combination to split the current window vertically:

20 Screen Command Examples to Manage Linux Terminals

In addition to this, we can also use the ctrl-a tab key combination switch between the regions and the ctrl-a X key combination to close the current region.

17. Enable Screen Logging in Linux

Sometimes it is important to record what you have done while you are in the console. Let’s say you are a Linux Administrator who manages a lot of Linux servers.

With this screen logging, you don’t need to write down every single command that you have done. To activate the screen logging function, just press “Ctrl-A” and “H“. (Please be careful, we use a capital ‘H’ letters. Using non-capital ‘h’, will only create a screenshot of the screen in another file named hardcopy).

At the bottom left of the screen, there will be a notification that tells you to like: Creating logfile “screenlog.0“. You will find a screenlog.0 file in your home directory.

This feature will append everything you do while you are in the screen window. To close the screen to log running activity, press “Ctrl-A” and “H” again.

Another way to activate the logging feature, you can add the parameter “-L” when the first time running the screen. The command will be like this.

pungki@mint ~ $ screen -L

18. Lock Linux Terminal Screen

The screen also has a shortcut to lock the screen. You can press the “Ctrl-A” and “x” shortcuts to lock the screen. This is handy if you want to lock your screen quickly. Here’s a sample output of the lock screen after you press the shortcut.

Screen used by Pungki Arianto  on mint.
Password:

You can use your Linux password to unlock it.

19. Add Password to Screen Session

For security reasons, you may want to put the password to your screen session. A Password will be asked whenever you want to re-attach the screen. This password is different from the Lock Screen mechanism above.

To make your screen password protected, you can edit the “$HOME/.screenrc” file. If the file doesn’t exist, you can create it manually. The syntax will be like this.

password crypt_password

To create the “crypt_password” above, you can use the “mkpasswd” command on Linux. Here’s the command with the password “pungki123“.

pungki@mint ~ $ mkpasswd pungki123
l2BIBzvIeQNOs

mkpasswd will generate a hash password as shown above. Once you get the hash password, you can copy it into your “.screenrc” file and save it. So the “.screenrc” file will be like this.

password l2BIBzvIeQNOs

Next time you run the screen and detach it, a password will be asked when you try to re-attach it, as shown below:

pungki@mint ~ $ screen -r 5741
Screen password:

Type your password, which is “pungki123” and the screen will re-attach again.

After you implement this screen password and press “Ctrl-A” and “x“, then the output will be like this.

Screen used by Pungki Arianto on mint.
Password:
Screen password:

A Password will be asked to you twice. The first password is your Linux password, and the second password is the password that you put in your .screenrc file.

20. Leaving Screen Terminal Session

There are 2 (two) ways to leave the screen. First, we are using “Ctrl-A” and “d” to detach the screen. Second, we can use the exit command to terminate the screen. You also can use “Ctrl-A” and “K” to kill the screen.

Screen Command Cheat Sheet

Command Description
screen -S <session_name></session_name> Start a new session with session name.
screen -ls List running sessions / screens.
screen -x Attach to a running session.
screen -r <session_name></session_name> Attach to a running session with name.
screen -d <session_name></session_name> Detach a running session.
Ctrl-a c Create new window.
Ctrl-a Ctrl-a Change to last-visited active window.
Ctrl-a <number></number> Change to window by number.
Ctrl-a ' <number or title></number> Change to window by number or name.
Ctrl-a n or Ctrl-a <space></space> Change to next window in list.
Ctrl-a p or Ctrl-a <backspace></backspace> Change to previous window in list.
Ctrl-a " See window list.
Ctrl-a w Show window bar.
Ctrl-a k Kill current window.
Ctrl-a \ Kill all windows.
Ctrl-a A Rename current window.
Ctrl-a S Split display horizontally.
Ctrl-a | or Ctrl-a V Split display vertically.
Ctrl-a tab Jump to next display region.
Ctrl-a X Remove current region.
Ctrl-a Q Remove all regions but the current one.
Ctrl-a H Enable logging in the screen session.
Ctrl-a x Lock (password protect) display.

That’s some of the screen command usage on daily basis. There are still a lot of features inside the screen command. You may see the screen man page for more detail.

Do you know of any other best example of the screen command in Linux? Let us know your views in the comments below.

The above is the detailed content of 20 Screen Command Examples to Manage Linux Terminals. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undress AI Tool

Undress AI Tool

Undress images for free

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

5 Best Open Source Mathematical Equation Editors for Linux 5 Best Open Source Mathematical Equation Editors for Linux Jun 18, 2025 am 09:28 AM

Are you looking for good software to write mathematical equations? If so, this article provides the top 5 equation editors that you can easily install on your favorite Linux distribution.In addition to being compatible with different types of mathema

SCP Linux Command – Securely Transfer Files in Linux SCP Linux Command – Securely Transfer Files in Linux Jun 20, 2025 am 09:16 AM

Linux administrators should be familiar with the command-line environment. Since GUI (Graphical User Interface) mode in Linux servers is not commonly installed.SSH may be the most popular protocol to enable Linux administrators to manage the servers

Gogo - Create Shortcuts to Directory Paths in Linux Gogo - Create Shortcuts to Directory Paths in Linux Jun 19, 2025 am 10:41 AM

Gogo is a remarkable tool to bookmark directories inside your Linux shell. It helps you create shortcuts for long and complex paths in Linux. This way, you no longer need to type or memorize lengthy paths on Linux.For example, if there's a directory

What is a PPA and how do I add one to Ubuntu? What is a PPA and how do I add one to Ubuntu? Jun 18, 2025 am 12:21 AM

PPA is an important tool for Ubuntu users to expand their software sources. 1. When searching for PPA, you should visit Launchpad.net, confirm the official PPA in the project official website or document, and read the description and user comments to ensure its security and maintenance status; 2. Add PPA to use the terminal command sudoadd-apt-repositoryppa:/, and then run sudoaptupdate to update the package list; 3. Manage PPAs to view the added list through the grep command, use the --remove parameter to remove or manually delete the .list file to avoid problems caused by incompatibility or stopping updates; 4. Use PPA to weigh the necessity and prioritize the situations that the official does not provide or require a new version of the software.

Install LXC (Linux Containers) in RHEL, Rocky & AlmaLinux Install LXC (Linux Containers) in RHEL, Rocky & AlmaLinux Jul 05, 2025 am 09:25 AM

LXD is described as the next-generation container and virtual machine manager that offers an immersive for Linux systems running inside containers or as virtual machines. It provides images for an inordinate number of Linux distributions with support

How to create a file of a specific size for testing? How to create a file of a specific size for testing? Jun 17, 2025 am 09:23 AM

How to quickly generate test files of a specified size? It can be achieved using command line tools or graphical software. On Windows, you can use fsutilfilecreatenew file name size to generate a file with a specified byte; macOS/Linux can use ddif=/dev/zeroof=filebs=1Mcount=100 to generate real data files, or use truncate-s100M files to quickly create sparse files. If you are not familiar with the command line, you can choose FSUtilGUI, DummyFileGenerator and other tool software. Notes include: pay attention to file system limitations (such as FAT32 file size upper limit), avoid overwriting existing files, and some programs may

How to install Linux alongside Windows (dual boot)? How to install Linux alongside Windows (dual boot)? Jun 18, 2025 am 12:19 AM

The key to installing dual systems in Linux and Windows is partitioning and boot settings. 1. Preparation includes backing up data and compressing existing partitions to make space; 2. Use Ventoy or Rufus to make Linux boot USB disk, recommend Ubuntu; 3. Select "Coexist with other systems" or manually partition during installation (/at least 20GB, /home remaining space, swap optional); 4. Check the installation of third-party drivers to avoid hardware problems; 5. If you do not enter the Grub boot menu after installation, you can use boot-repair to repair the boot or adjust the BIOS startup sequence. As long as the steps are clear and the operation is done properly, the whole process is not complicated.

NVM - Install and Manage Multiple Node.js Versions in Linux NVM - Install and Manage Multiple Node.js Versions in Linux Jun 19, 2025 am 09:09 AM

Node Version Manager (NVM) is a simple bash script that helps manage multiple Node.js versions on your Linux system. It enables you to install various Node.js versions, view available versions for installation, and check already installed versions.NV

See all articles