Situatie
The Linux screen command is a versatile tool that allows you to run terminal applications in the background and switch back to them when needed. It supports split-screen displays and can be used over SSH connections, even after disconnecting and reconnecting. With screen, you can create new windows, run multiple processes, detach and reattach sessions, and share sessions between multiple users in real-time.
With the Linux screen
command, you can push running terminal applications to the background and pull them forward when you want to see them. It also supports split-screen displays and works over SSH connections, even after you disconnect and reconnect!
What Is the screen Command?
The screen
command is a terminal multiplexer, and it’s absolutely packed with options. To say it can do a lot is the granddaddy of understatements. The man page runs to over 4,100 lines.
The following are the most common cases in which you would use the screen
command, and we’ll cover these further in this article:
- The standard operation is to create a new window with a shell in it, run a command, and then push the window to the background (called “detaching”). When you want to see how your process is doing, you can pull the window to the foreground again (“reattach”) and use it again. This is great for long processes you don’t want to accidentally terminate by closing the terminal window.
- Once you’ve got a
screen
session running, you can create new windows and run other processes in them. You can easily hop between windows to monitor their progress. You can also split your terminal window into vertical or horizontal regions, and display your variousscreen
windows in one window. - You can connect to a remote machine, start a
screen
session, and launch a process. You can disconnect from the remote host, reconnect, and your process will still be running. - You can share a
screen
session between two different SSH connections so two people can see the same thing, in real-time.
Solutie
Pasi de urmat
Install Linux screen
To install screen
on ubuntu, use this command:
sudo apt-get install screen
To install screen
on Manjaro, use the following command:
sudo pacman -Sy screen
On Fedora, you type the following:
sudo dnf install screen
Getting Started with Linux screen
To start screen
, simply type it as shown below and hit Enter:
screen
You’ll see a page of license information. You can press the Space bar to read the second page or Enter to return to the command prompt.
You’re left at the command prompt, and nothing much seems to have happened. However, you’re now running a shell inside a multiplexed terminal emulator. Why is this a good thing? Well, let’s start a process that’s going to take a long time to complete. We’ll download the source code for the latest Linux kernel and redirect it into a file called latest_kernel.zip
.
To do so, we type the following:
curl https://cdn.kernel.org/pub/linux/kernel/v5.x/linux-5.5.9.tar.xz > latest_kernel.zip
Our download begins, and the curl
output shows us the progress.
Using Named screen Sessions on Linux
You can use the -S
(session name) option to name your screen
session. If you use a memorable name rather than the numerical identity of the session, it’s more convenient to reconnect to a session. We type the following to name our session “bigfile”:
screen -S bigfile
When screen
launches our session, we see a blank window with a command prompt. We’re going to download a big file, so we can use a long-running process as an example.
We type the following:
curl http://ipv4.download.thinkbroadband.com/1GB.zip > bigfile.zip
When the download starts, we press Ctrl+A, and then press D to detach the session. We type the following to use the -ls
(list) option with screen
to see the details of our detached session:
screen -ls
Using screen with Multiple Windows
So far, we’ve used screen
to place a single process in the background in a detached window. However, screen
is capable of doing much more than that. Next, we’ll run a few processes that allow us to monitor some aspects of our computer.
We type the following to start a screen session called “monitor”:
screen -S monitor
Leave A Comment?