The screen
command is a popular and powerful tool for managing multiple terminal sessions on Linux. It allows users to create and manage multiple virtual terminals, or “screens”, within a single terminal window, and switch between them easily.
In this tutorial, we will show you how to use the screen
command on Linux. We will assume that you have already installed a Linux operating system on your system.
Prerequisites
Before you begin, you will need the following:
- A system running a Linux operating system
- A user with administrative privileges on your system
Installing the screen
Command
To use the screen
command on Linux, you need to install the screen
package.
On most Linux distributions, the screen
package is included in the default package repositories. To install the screen
package, use the package manager of your Linux distribution.
For example, on Ubuntu and Debian, you can use the apt
package manager to install the screen
package:
sudo apt update
sudo apt install screen
On CentOS and Fedora, you can use the yum
package manager to install the screen
package:
sudo yum update
sudo yum install screen
On Arch Linux and its derivatives, you can use the pacman
package manager to install the screen
package:
sudo pacman -Sy
sudo pacman -S screen
After installing the screen
package, you can use the screen
command in your terminal.
Using the screen
Command
To use the screen
command, open a terminal window and run the following command:
screen
This will start a new screen
session, and create a new virtual terminal within the terminal window.
You can use the new virtual terminal just like a regular terminal. You can run commands, execute programs, and access files and directories.
To switch between the virtual terminals, you can use the Ctrl + a
and n
or p
keys. The Ctrl + a
key combination is the default control key for screen
, and n
or p
means next or previous.
For example, to switch to the next virtual terminal, press Ctrl a**
followed by**n**
. To switch to the previous virtual terminal, press** Ctrl + a**
followed by**p
.
To create a new virtual terminal, press Ctrl + a
followed by c
. This will create a new virtual terminal and switch to it automatically.
To close a virtual terminal, press Ctrl + a
followed by d
. This will detach the virtual terminal from the screen
session, but the virtual terminal will continue running in the background.
To list all the virtual terminals that are running in the screen
session, press Ctrl + a
followed by w
. This will display a list of the virtual terminals and their status.
To reattach a detached virtual terminal, use the screen
command with the -r
option and the session name or number.
For example, to reattach the first detached virtual terminal, run the following command:
screen -r 0
To reattach a detached virtual terminal that has a specific name, run the following command:
screen -r SESSION_NAME
For example, if the name of the detached virtual terminal is myterminal
, run the following command:
screen -r myterminal
Conclusion
In this tutorial, you learned how to use the screen
command on Linux. You learned how to create and manage multiple virtual terminals, and how to switch between them and attach and detach them from the screen
session.
With the screen
command, you can easily manage multiple terminal sessions and run multiple programs and commands simultaneously.