Basic Linux Screen Commands
Linux screen is a very useful tool that comes pre-installed on almost all server distributions. So why not use it to make your lives a little better?
Why use screen?
Screen lets you do the following:
- Run a long running process without maintaining an active shell session
- Use multiple shell windows from a single SSH session
- Keep a shell active even after network disconnects
These are just some of the most popular and basic features of
screen and what will be couvered in this article
Once installed, starting screen is as simple as invoking it just like any other command
This will land you in a screen instance.
Reattaching to a running screen instance
$ screen -r
If there are multiple screen instances running, the command will list all running instances instead of attaching to an instance like so
$ screen -r There are several suitable screens on: 31917.pts-5.ubuntu (Detached) 31844.pts-0.ubuntu (Detached) Type "screen [-d] -r [pid.]tty.host" to resume one of them.
In this case run the same command with the screen ID like so:
$ screen -r 31917.pts-5.ubuntu
Reattaching to a running screen instance after a network issue
Sometimes, after a network disconnect, screen might error you out when trying to reattach
$ screen -r 31844.pts-0.ubuntu There is a screen on: 31917.pts-5.ubuntu (09/09/2018 05:29:24 AM) (Attached) There is no screen to be resumed matching 31844.pts-0.ubuntu.
In this case, just use the
$ screen -r -d 31844.pts-0.ubuntu
Basic commands, once inside a screen
Screen uses the command
Ctrl-a that’s the control key and a lowercase
a as a signal to send commands to screen
instead of the shell.
screen help page
creates a new window
This command switches you to the next window
This command switches you to the previous window
This command switches you to detach from a window, This will land you on your shell but your windows are still there and you can always reattach to them later.
This command closes the screen window. You have to close all screen windows to terminate the session.