Screen. A remote desktop for your terminal window

Today I want to talk about Screen, a command that is very handy, but not used very often.

What’s it good for?

You know the fact that you lose your work in your terminal window, whenever you lose the connection to the remote system. To avoid this you can run a little tool called screen. Screen is used to detach from a console session without killing the actual shell or terminating your running processes. That means that all programs and tasks that were running in the shell, continuing to run. You can disconnect from a session on one PC and connect to the same session from another PC.

What is the advantage?

Imagine that you want to monitor a job, that will run for a while and you have to move your workplace in the meantime. Or you don’t want to lose the output in a console window.

How to use it.

 If you type the command screen on the console, you will not see any change on the console. What you might see is that the window title slightly changed. Now you are in a screen session. Try to start top on the console.

screen first pic

I opened a screen session in the top console window.

The terminal window behaves the same way it did before. With [ctrl]+[a] [c] you can open another virtual terminal. You see a new prompt and the running top is now running somewhere in the background. At the new prompt you can start another program. With [ctrl]+[a] [n] (next) or [ctrl]+[a] [p] (previous) is it possible to browse through the open terminals.

Screen 2

Here i started a script in the second virtual console.

To show what screens are currently running use screen -ls.

Screen 3

screen -ls shows the available screen sessions.

Now we can connect another terminal to our screen session. With screen -r screen.PID,  you attach a terminal window to your terminal session. In fact that you only have one screen session running on the system a screen -r connects you to that session.

Screen4

The second window is now connected to the screen session.

Now start an application in the second window.

Screen6

I started a script in the lower terminal window

Use [ctrl]+[a] [n] to find this process in the upper window.

Screen7

Both terminals show the same output.

Now use [ctrl]+[a] [d] to detach both terminals from the screen session.

Screen9

Both terminals are now detached.

As you can see is the screen session still active in the background.

Screen11

I connected a new terminal to the session.

So, although all terminals are detached from the session, it is still running in the background, waiting for a reconnect/attach. To terminate the screen session, you can use [CTRL]+[a] [Ctrl]+[\] or you can switch to the command mode by using [Ctrl]+[a] [:] and type quit at the colon.

Useful commands

Every command starts with [Ctrl]+[a], followed by a character, symbol or another [Ctrl]-sequence.

[Ctrl]+[a] ["] Lists the windows in the screen session
[Ctrl]+[a] [1] Jumps to window 1
[Ctrl]+[a] [c] Create a new window in this session
[Ctrl]+[a] [C] Clear the screen
[Ctrl]+[a] [d] Detach from screen session
[Ctrl]+[a] [H] Starts/Ends a screen log
[Ctrl]+[a] [i] Show information about the current window
[Ctrl]+[a] [k] Destroy the current window
[Ctrl]+[a] [n] Jumps to the next window
[Ctrl]+[a] [p] Jumps to the previous window
[Ctrl]+[a] [i] Show information about the current window
[Ctrl]+[a] [S] Split the current window into two regions
[Ctrl]+[a] [TAB] Move between regions
[Ctrl]+[a] [X] Kill the current region
[Ctrl]+[a] [Q] Delete all regions but the current one
[Ctrl]+[a] [.] Writes a .termcap file
[Ctrl]+[a] [Ctrl]+[\] Kill all windows and terminate screen

 

About Juergen Caris

I am 54yo, MSc(Dist) and BSc in Computer Science, German and working as a Senior Server Engineer for the NHS Lothian. I am responsible for the patient management system, called TrakCare. I am a UNIX/Linux guy, working in this sector for more than 20 years now. I am also interested in robotics, microprocessors, system monitoring, Home automation and programming.
This entry was posted in Linux. Bookmark the permalink.

15 Responses to Screen. A remote desktop for your terminal window

  1. armor games says:

    Wow, superb weblog layout! How long have you been running a blog for? you made blogging glance easy. The entire look of your site is fantastic, as well as the content material!

  2. Pingback: Edwin Austin Abbey

  3. My brother suggested I would possibly like this website. He used to be totally right. This post truly made my day. You cann’t consider simply how a lot time I had spent for this info! Thank you!

  4. Wow! Thank you! I constantly needed to write on my blog something like that. Can I take a portion of your post to my blog?

  5. Chose to just stop by as well as tell you just how a lot I enjoy this website :) The posts here are usually interesting at the very least.

  6. Spot on with this write-up, I seriously feel this amazing site needs much more attention. I’ll probably be back again to read through more, thanks for the info!

  7. I think this is among the most significant information for me. And i am glad reading your article. But should remark on some general things, The web site style is ideal, the articles is really excellent : D. Good job, cheers

  8. Julia says:

    perfectly.
    It informational resource, I’ll bookmark it and visit it again!

  9. Good info. Lucky me I ran across your website by accident (stumbleupon). I’ve book marked it for later!

  10. It’s exhausting to search out educated folks on this topic, however you sound like you realize what you’re talking about! Thanks

  11. Oh my goodness! an amazing article dude. Thank you Nonetheless I’m experiencing situation with ur rss . Don’t know why Unable to subscribe to it. Is there anybody getting equivalent rss downside? Anyone who is aware of kindly respond. Thnkx

  12. Anonymous says:

    Useful information shared..Iam very happy to read this article..thanks for giving us nice info.Fantastic walk-through. I appreciate this post.

  13. I am typically to running a blog and i really admire your content. The article has really peaks my interest. I’m going to bookmark your website and keep checking for brand new information.

  14. KSS Spa says:

    This actually answered my drawback, thank you!

  15. KIMAK KAU says:

    Everything is very open with a really clear description of the issues.
    It was truly informative. Your website is useful. Thank you for sharing!

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>