Skip to content

How to use Screen on Linux

Screen on Linux is a popular command-line program that lets you multiplex between interactive shells.

What that means is, you can use screen to save and restore running of commands.

Screen in action

The best way to test this out is to SSH into a server.

Code language: Bash (bash)

At this stage, you can execute man screen to learn all the commands available to you.

You can issue a screen -list to show all screen sessions that may already be open.

$ screen -list No Sockets found in /run/screen/S-user.
Code language: Bash (bash)

If there are no sessions, then you can simply begin by typing screen and hitting Return.

You will be presented with this the first time around, you can press Space or Return to continue at any time.

Screen on Linux

Now you can execute some long-running script or otherwise over SSH and not worry about being timed-out, logged out or cut off midway.

Simply press Ctrl+A followed by Ctrl+D to exit out while saving the state.

Listing, Retrieving and Destroying Shells

Now in the parent shell, type screen -list one more time to see the shell still active, that can be rejoined.

$ screen -list There is a screen on: 3560.pts-0.server (02/09/20 09:21:12) (Detached)
Code language: Bash (bash)

If there is only one entry in this list, type screen -r to rejoin it, otherwise, type screen -r <PTRR_ID>.

For example in the above screen -r 3560.pts-0.server.

To terminate a shell session, simply go into and press Ctrl+D to destroy it. Now if you type screen -list once again, there will be no sessions, just how it started out.

See also  How to Force a Redeploy in Kubernetes
Notify of
Inline Feedbacks
View all comments
Would love your thoughts, please comment.x