How to Use Linux’s screen Command

A Linux terminal on a laptop with other terminal sessions superimposed behind it.
fatmawati achmad zaenuri/Shutterstock

With the Linux display screen command, you may push working terminal functions to the background and pull them ahead whenever you need to see them. It additionally helps split-screen shows and works over SSH connections, even after you disconnect and reconnect!

What Is the display screen Command?

The display screen command is a terminal multiplexer, and it’s completely full of choices. To say it may do quite a bit is the granddaddy of understatements. The person web page runs to over 4,100 strains.

The next are the most typical circumstances in which you’d use the display screen command, and we’ll cowl these additional on this article:

  • The usual operation is to create a brand new window with a shell in it, run a command, after which push the window to the background (known as “detaching”). If you need to see how your course of is doing, you may pull the window to the foreground once more (“reattach”) and use it once more. That is nice for lengthy processes you don’t need to by chance terminate by closing the terminal window.
  • When you’ve acquired a display screen session working, you may create new home windows and run different processes in them. You’ll be able to simply hop between home windows to watch their progress. You’ll be able to additionally break up your terminal window into vertical or horizontal areas, and show your numerous display screen home windows in a single window.
  • You’ll be able to connect with a distant machine, begin a display screen session, and launch a course of. You’ll be able to disconnect from the distant host, reconnect, and your course of will nonetheless be working.
  • You’ll be able to share a display screen session between two completely different SSH connections so two folks can see the identical factor, in real-time.

Putting in display screen

To put in display screen on ubuntu, use this command:

sudo apt-get set up display screen

The "sudo apt-get install screen" command in a terminal window.

To put in display screen on Manjaro, use the next command:

sudo pacman -Sy display screen

The "sudo pacman -Sy screen" command in a terminal window.

On Fedora, you sort the next:

sudo dnf set up display screen

The "sudo dnf install screen" command in a terminal window.

Getting Began with display screen

To begin display screen, merely sort it as proven beneath and hit Enter:

display screen

The "screen" command in a terminal window.

You’ll see a web page of license data. You’ll be able to press the House bar to learn the second web page or Enter to return to the command immediate.

The "screen" command license information in a terminal window.

You’re left on the command immediate, and nothing a lot appears to have occurred. Nevertheless, you’re now working a shell inside a multiplexed terminal emulator. Why is that this a great factor? Effectively, let’s begin a course of that’s going to take a very long time to finish. We’ll obtain the supply code for the newest Linux kernel and redirect it right into a file known as latest_kernel.zip.

To take action, we sort the next:

curl https://cdn.kernel.org/pub/linux/kernel/v5.x/linux-5.5.9.tar.xz > latest_kernel.zip

The "curl https://cdn.kernel.org/pub/linux/kernel/v5.x/linux-5.5.9.tar.xz > latest_kernel.zip" command in a terminal window.

Our obtain begins, and the curl output reveals us the progress.

The output from the "curl https://cdn.kernel.org/pub/linux/kernel/v5.x/linux-5.5.9.tar.xz > latest_kernel.zip" command in a terminal window.

We will’t present you a picture of the subsequent bit, as a result of it’s a keystroke sequence. You sort Ctrl+A, launch these keys, after which press d to detach the display screen.

The obtain course of continues to be working however the window exhibiting the obtain is eliminated. You’re returned to the terminal window from which you launched the display screen session. A message tells you {that a} display screen window labeled 23167.pts-0.howtogeek has been indifferent.

You want the quantity from the beginning of the window identify to reattach it. If you happen to overlook it, you may all the time use the -ls (checklist) choice, as proven beneath, to get an inventory of the indifferent home windows:

display screen -ls

The "screen -ls" command in a terminal window.

If you’re prepared, you should use the -r (reattach) choice and the variety of the session to reattach it, like so:

display screen -3 23167

The "screen -3 23167" command in a terminal window.

The window that’s been working away within the background is now introduced again to your terminal window as if it had by no means left.

A reattached screen session restored to the terminal window.

If it’s a course of that’s going to run by to its conclusion it is going to ultimately full. If it’s a continuous course of, you’ll ultimately need to terminate it. Both means, when the method ends, you may sort exit to exit from the display screen. Alternatively, you may press Ctrl+A, after which Okay to forcibly kill a window.

Sort the next command:

exit

The "exit" command in a terminal window.

You’re returned to your earlier terminal window, which is able to nonetheless present the command you used to reattach the window. As a result of we closed our one and solely indifferent window, we get a message that display screen is terminating.

The "screen" command terminating message in a terminal window.

RELATED: How one can Use curl to Obtain Information From the Linux Command Line

Utilizing Named display screen Classes

You should use the -S (session identify) choice to call your display screen session. If you happen to use a memorable identify relatively than the numerical identification of the session, it’s extra handy to reconnect to a session. We sort the next to call our session “bigfile”:

display screen -S bigfile

The "screen -S bigfile" command in a terminal window.

When display screen launches our session, we see a clean window with a command immediate. We’re going to obtain an enormous file, so we are able to use a long-running course of for example.

We sort the next:

curl http://ipv4.obtain.thinkbroadband.com/1GB.zip > bigfile.zip

The "curl http://ipv4.download.thinkbroadband.com/1GB.zip > bigfile.zip" command in a terminal window.

When the obtain begins, we press Ctrl+A, after which press D to detach the session. We sort the next to make use of the -ls (checklist) choice with display screen to see the small print of our indifferent session:

display screen -ls

The "screen -ls" command in a terminal window.

Behind the numeric identifier (23266), we see the identify of our session (bigfile). We sort the next, together with the session’s identify, to reattach it:

display screen -r bigfile

The "screen -r bigfile" command in a terminal window.

We’re reconnected to our obtain window and see the lengthy obtain continues to be in progress.

Curl download output in a reattached screen session in a terminal window.

When the obtain is full, we sort exit to shut the session window.

Utilizing display screen with A number of Home windows

Thus far, we’ve used display screen to put a single course of within the background in a indifferent window. Nevertheless, display screen is able to doing far more than that. Subsequent, we’ll run a couple of processes that permit us to watch some facets of our pc.

We sort the next to start out a display screen session known as “monitor”:

display screen -S monitor

The "screen -S monitor" command in a terminal window.

On the command immediate in our new window session, we’ll launch dmesg and use the -H (human-readable) and -w (wait for brand spanking new messages) choices. This may show the kernel buffer messages; new messages will seem as they happen.

We sort the next:

dmesg -H -w

The "dmesg -H -w" command in a terminal window.

The prevailing messages seem. We’re not returned to the command immediate as a result of dmseg is ready for brand spanking new messages, and can show them as they arrive.

The "dmsesg" output in a terminal window.

RELATED: How one can Use the dmesg Command on Linux

We need to run one other software, so we’d like a brand new display screen window. We press Ctrl+A, after which C to create a contemporary window. We’re going to make use of watch to repeatedly run vmstat, so we get a continuously up to date show of the digital reminiscence utilization on our pc.

On the new command immediate, we sort the next:

watch vmstat

The "watch vmstat" command in a terminal window.

The vmstat output seems and updates each two seconds.

The "vmstat" output in a terminal window.

Our two processes at the moment are working. To hop between the display screen home windows, you press Ctrl+A, and the variety of the window. The primary one we created is window zero (0), the subsequent is window 1, and so forth. To hop to the primary window (the dmesg one), we press Ctrl+A and 0.

Returning to the "dmesg" screen in a terminal window.

If we press Ctrl+A and 1, it takes us again to the vmstat window.

Returning to the "vmstat" screen in a terminal window.

That’s fairly nifty! We will press Ctrl+A, after which D to detach from this session; we are able to reattach later. Each classes will nonetheless be working. Once more, to change between the home windows, we press Ctrl+A and the quantity (Zero or 1) of the window we need to swap to.

Let’s go to the subsequent step and think about each screens in a single window. If you do that, you’ll stretch your terminal window to a dimension that makes this step helpful. Our examples are constrained to the scale of our screenshots, so our home windows will look a little bit cramped.

To do that, we press Ctrl+A, after which Shift+S (a capital “S” is required).

The window splits into two “areas.”

A "screen" window session split into two horizontal regions in a terminal window.

The highest area nonetheless shows vmstat, and the underside area is clean. The cursor is highlighted within the screenshot beneath. To maneuver it to the decrease area, we press Ctrl+A, after which Tab.

A "screen" window session split into two horizontal regions with cursor in the bottom region in a terminal window.

The cursor strikes to the decrease area, which actually is simply an empty area. It isn’t a shell, so we are able to’t sort something in it. To get a helpful show, we press Ctrl+A, after which press “0” to show the dmesg window on this area.

The "screen" session with a horizontal split pane showing a different process in each region in a terminal window.

This offers us each dwell outputs in a single break up window. If we press Ctrl+A and D to detach the window, after which reattach it, we’ll lose the split-pane view. Nevertheless, we are able to restore it with the next keyboard shortcuts:

  • Ctrl+A, S: Cut up the window horizontally.
  • Ctrl+A, Tab: Transfer to the decrease area.
  • Ctrl+A, 0: Show window zero within the decrease area.

We will take issues even a step additional. We’ll now break up the decrease pane vertically, and add a 3rd course of to the show. With the cursor within the decrease area, we press Ctrl+A and C to create a brand new window with a shell in it. The decrease area shows the brand new window and offers us a command immediate.

A "screen" session with a horizontal split pane showing a new window in the lower region in a terminal window.

Subsequent, we run the df command to verify file system utilization:

df

A "screen" session with a horizontal split pane, and "df" typed in the lower region in a terminal window.

Once we see df working, we hit Ctrl+A and the pipe character (|). This splits the decrease area vertically. We press Ctrl+A and Tab to maneuver to the brand new area. Subsequent, we press Ctrl+A and Zero to show the dmesg window.

A "screen" session showing three panes in a terminal window.

You may as well transfer from area to area, and add extra vertical or horizontal splits. Listed below are some extra helpful key combos:

  • Ctrl+A: Hop forwards and backwards between the present and former areas.
  • Ctrl+A, Q: Shut all areas besides the present one.
  • Ctrl+A, X: Shut the present area.

Utilizing display screen Over SSH

With display screen, you can begin a window session, detach it so it’s nonetheless working within the background, log out or again in, and reattach the session.

Let’s make an SSH connection to our pc from a unique one with the ssh command. We now have to offer the identify of the account with which we’re going to attach and the deal with of the distant pc.

For our instance, we sort the next:

ssh [email protected]

The "ssh dave@192.168.4.30" command in a terminal window.

After we authenticate on the distant pc and log in, we sort the next to start out a display screen session known as “ssh-geek”:

display screen -S ssh-geek

The "screen -S ssh-geek" command in a terminal window.

For demonstration functions, we’ll run prime within the display screen window, however you possibly can begin any long-running or infinite course of.

We sort the next:

prime

The "top" command in a terminal window.

As soon as prime is working within the window, we hit Ctrl+A, after which D to detach the window.

The "top" process running in a "screen" window in a terminal window.

We’re returned to the unique, distant terminal window.

User returned to their original terminal window

If we sort exit, as proven beneath, it disconnects the SSH session and we’re again on our native pc:

exit

The "exit" command in a terminal window.

We sort the next to reconnect:

ssh [email protected]

The "ssh dave@192.168.4.30" command in a terminal window.

After we’re reconnected and logged in, we are able to sort the next to reattach the display screen session:

display screen -r ssh-geek

The "screen -r ssh-geek" command in a terminal window.

We’re now reconnected to our still-running occasion of prime.

The "top" process running in a terminal window.

That is nice if you wish to begin a course of on one machine, after which decide up wherever you left off on one other.

RELATED: How one can Create and Set up SSH Keys From the Linux Shell

Sharing a display screen Session

You may as well use a display screen session to permit two folks to see and work together with the identical window. Let’s say somebody working Fedora on his pc desires to hook up with our Ubuntu server.

He would sort the next:

ssh [email protected]

The "ssh dave@192.168.4.30" command in a terminal window.

After he’s related, he begins a display screen session known as “ssh-geek” utilizing the -S (session identify) choice. He additionally makes use of the -d (detach) and -m (enforced creation) choices to create a brand new display screen session that’s already indifferent.

He varieties the next:

display screen -d -m -S ssh-geek

The "screen -d -m -S ssh-geek" command in a terminal window.

He varieties the next, utilizing the -X (multiscreen mode) choice to connect the session:

display screen -X ssh-geek

The "screen -X ssh-geek" command in a terminal window.

On a Manjaro pc, one other particular person connects to the Ubuntu pc with the identical account credentials, as proven beneath:

ssh [email protected]

The "ssh dave@192.168.4.1" command in a terminal window.

As soon as she’s related, she varieties the display screen command and makes use of the -X (multiscreen mode) choice to hitch the identical window session, like so:

display screen -X ssh-geek

The "screen -X ssh-geek" command in a terminal window.

Now, something both particular person varieties, the opposite will see. For instance, when one particular person points the date command, they each see it because it’s typed, in addition to its output.

The "date" command in a terminal window.

Output from the "date" command in a terminal window.

Each folks at the moment are sharing a display screen session that’s working on a distant Ubuntu pc.


For a bit of software program that first noticed the sunshine of day in 1987, display screen nonetheless packs a great productiveness wallop. Familiarizing your self with it is going to be time effectively spent!

RELATED: 37 Vital Linux Instructions You Ought to Know

About Dave McKay

Check Also

How to Use Microsoft Office’s Panning Hand Instead of the Scroll Bar

Older variations of Microsoft Workplace had a visual “panning hand” choice that allow you to …

Leave a Reply

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