Have you ever heard of the Linux Screen Command? It’s an incredibly powerful tool that allows you to take control of multiple programs in a single terminal window. With the Linux Screen Command, you can easily manage multiple programs, even if they’re running in different directories. You can even switch between programs without having to close or restart them. It’s an incredibly efficient way to work in Linux.
The Screen Command is incredibly easy to use. All you have to do is type in the screen command to open a new window, and then from there you can run any commands you want. You can also use it to run multiple programs simultaneously, which can be incredibly useful for multitasking. And if you need to take a break, you can always suspend the screen command and come back later.
This article will cover the basics of installing and using the Linux screen command. By the end of this tutorial, you will be able to create and attach to screen sessions, split the screen into multiple windows, and detach, reattach from exiting screen sessions.
Step 1: Install Screen
Before you can use the screen command, you will need to install it on your system. On most Linux distributions, the screen is included in the default package repositories, so you can install it using your package manager.
- For example, on an Ubuntu, Debian, and Linux Mint system, you can install a screen package using the following command:
sudo apt update && sudo apt install screen
- On a CentOS, RHEL, and Fedora system, you can install the screen package using the following command:
sudo dnf install screen
Step 2: Create a New Screen Session
To create a new screen session, simply run the screen command. This will launch a new terminal window within the screen, and you can use it just like any other terminal window.
For example, to create a new screen session and start a new bash shell, you would enter the following command:
You can also specify a name for your screen session when you create it. To do this, use the “-S” command line option followed by the name of your session. For example:
screen -S mysession bash
This command will create a new session named “mysession”.
Step 3: Screen Command Keyboard Shortcuts
In the previous step, you activated the screen session in your terminal. Now, you should be aware of its uses. You can manage the screen session using the keyboard shortcuts. Using the keystokes you can create new windows, attach, detach, rename, and many more with the screen session.
Here are some commonly used keyboard shortcuts, that help you to work with screen:
Ctrl a and c: Create a new window
Ctrl a and ": List all open windows
Ctrl a and n: Go to the next window
Ctrl a and p: Go to the previous window
Ctrl a and 0: Switch to window 0 (or other numbered window)
Ctrl a and S: Split the screen horizontally into regions
Ctrl a and |: Split The screen vertically into regions
Ctrl a and tab: Switch focus between areas of the split screen.
Ctrl a and d: Detach screen from terminal
Ctrl a and A: Set the window title
Ctrl a and x: Lock the current session
Ctrl a and ?: Show key bindings/command names
To use the above key bindings, keep pressing the CTRL key and then hit “a” and then hit the required key.
Step 3: Detach from a Screen Session
To detach from a screen session and return to your regular terminal window, use the “CTRL a and d” keys. This will leave the screen session running in the background, allowing you to reconnect to it later.
For example, to detach from the screen session that you created in step 2, press the keyboard shortcut: “CTRL a and d”
Step 4: List Available Screen Sessions
To view a list of available screen sessions, use the screen -ls command. This will show you a list of all screen sessions that are currently running on your system, along with their session names and process IDs.
For example, if you have a screen session named “mysession” running, the screen -ls command would output something like this:
OutputThere is a screen on: 128506.mysession (Attached) 1 Socket in /run/screen/S-rahul.
Step 5: Reattach to a Screen Session
To reconnect to a screen session that you have previously detached from, use the screen
-r command followed by the name or process ID of the session.
For example, to reconnect to the “mysession” screen session that you created in step 2, you would enter the following command:
screen -r mysession
If you have multiple screen sessions running and you are not sure which one you want to reconnect to, you can use the
`screen -ls` command to view a list of available sessions, as described in step 4.
Step 6: Split the Screen into Multiple Windows
Once you are attached to a screen session, you can split the screen into multiple windows.
- Press the
CTRL a and Skeys to split the current region horizontally into two new ones.
- Press the
CTRL a and |keys to split the current region vertically into two new ones.
- Press the
CTRL a and TABkeys to switch between the windows.
In this tutorial, we covered the basics of installing and using the Linux screen command. With screen, you can create and attach to screen sessions, split the screen into multiple windows, and detach from screen sessions. You can use these techniques to run multiple terminal-based tasks simultaneously and easily switch between them.
I hope this tutorial has been helpful and that you are now comfortable using the Linux screen command. If you have any questions or need further assistance, feel free to leave a comment below.