Introduction to Screen
Screen is a linux application that can be used for creating multiple shell (bash) terminals from a single session. For example, if you have logged into a remote machine using ssh and would like access to multiple terminal windows, you can use screen to get the job done. So essentially, you can think of Screen as a window manager that will enable you to create multiple “Terminal Tabs” inside a single terminal session. So Screen acts as terminal emulator that multiplexes multiple terminal processes and each virtual terminal provides the same functionality of a regular terminal.
You can check whether Screen is already installed on your machine by starting a terminal and running (without the $ symbol):
[ecko_code_highlight language=”shell”]$ which screen[/ecko_code_highlight]
If it returns the following, then you are ready to use Screen.
If not, you can install it using the below command (assuming that you are running Ubuntu OS)
[ecko_code_highlight language=”shell”]$ sudo apt-get install screen[/ecko_code_highlight]
Running Screen and Commands
To start screen, just open a terminal and type:
[ecko_code_highlight language=”shell”]$ screen[/ecko_code_highlight]
Screen now automatically creates a window with a single virtual terminal, and you are now inside the virtual terminal. To control Screen behavior, you can use the command Ctrl-a. If you want check the available commands, you can use Ctrl-a and type ? to bring up the list of available commands.
Click on the blocks below to learn about some of the most commonly used commands in Screen:
[ecko_toggle style=”solid” state=”open” title=”Creating a New Screen“]To create a new screen, you can use Ctrl-a and c. This will create a new screen and your old screens are still active.[/ecko_toggle]
[ecko_toggle style=”solid” state=”closed” title=”Switching between Screens“]To switch between screens, you can use Ctrl-a and n OR Ctrl-a and p to go to either the “next” or the “previous” screen. Once you reach the last screen, these commands cycle back again.[/ecko_toggle]
[ecko_toggle style=”solid” state=”closed” title=”Logging information”]To log all information in a screen session, you can use Ctrl-a and H. This will create a logfile by name screenlog.0 and logs your entire screen session output.[/ecko_toggle]
[ecko_toggle style=”solid” state=”closed” title=”Detach/Re-attach Screen“]This is a very powerful screen option that enables you to detach from a screen session, and re-attach later. To detach a screen session, use Ctrl-a and d, and to re-attach to a save screen session, use Ctrl-a and r. Once you detach from an existing screen session, it will drop you to your previous shell. You can then reattach to your screen session at any time, and you can retrieve all the previously created screens.[/ecko_toggle]
[ecko_toggle style=”solid” state=”closed” title=”Lock your Screen(s)“]Once you have created some screen sessions, you can also lock your current screen session using Ctrl-a and x.[/ecko_toggle]
[ecko_toggle style=”solid” state=”closed” title=”Splitting Screens“]You can have multiple screens visible at the same time using the screen split view. You can split screens horizontally using the command Ctrl-a and S, or vertically using Ctrl-a and |.[/ecko_toggle]
Have fun using Screen!