How To Use Shortcuts For Screen Command.
What is screen comand?
At its core, screen is a terminal multiplexer. It enables users to open multiple virtual terminals within a single physical terminal or remotely accessed terminal. With screen, you can start long-running processes, keep them running even if your connection drops, detach from the sessions, and later reattach to them from another location.
In most Linux OS screen are preinstalled. If it’s not installed you need to install manually:
- Use the package manager of your Linux distribution to install screen. For example, on Ubuntu, you can use the following command: sudo apt-get install screen.
- On Red Hat Enterprise Linux (RHEL) or CentOS, you can use: sudo yum install screen or sudo dnf install screen.
- Basic Usage of screen
To initiate a new screen session, simply type:
This will create a new virtual terminal, and you can start working as you would in a regular terminal. To exit the session, press Ctrl + A followed by D. This detaches you from the session, allowing it to keep running in the background.
- Reattaching to screen Sessions
After detaching from a screen session, you can later reattach to it and resume your work. To list all available screen sessions, execute:
The output will display a list of available sessions along with their unique session IDs. To reattach to a specific session, use:
- Naming screen Sessions
By default, screen sessions are identified by session IDs, which can be cumbersome to remember. To make your life easier, you can give meaningful names to your sessions using the -S flag when starting a new session. For example:
Now, you can reattach to this session by using its name instead of the session ID:
- Managing Multiple Windows
Within a single screen session, you can create and manage multiple terminal windows, each functioning independently. To create a new window, press:
To switch between different windows, use:
If you want to switch directly to a specific window, press:
- Closing Windows
To close the current window, type exit. Be cautious as this only closes the window but not the underlying process. The process will continue running in the background.
- Splitting the Screen
One of the most useful features of screen is the ability to split the terminal window into multiple regions, displaying different terminal sessions simultaneously. To split the screen vertically, use:
To split the screen horizontally, use:
Switch between split screen regions by pressing:
- Copy and Paste
screen also allows you to copy and paste text between different windows within a session. To enter copy mode, press:
Use the arrow keys or the vi editor keybindings to navigate and select the text. To copy the selected text, press Enter. To paste the copied text, press:
- Exiting screen Sessions
To exit a screen session, ensure that all windows within the session are closed. Then, type:
This will terminate the screen session.
The Linux screen command is a powerful tool that enhances terminal multitasking and remote server management. By mastering the various features and shortcuts of screen, you can boost your productivity and efficiently manage multiple terminal sessions. Whether you are a system administrator, developer, or power user, screen is a valuable addition to your Linux toolkit. So, start exploring the capabilities of screen and unlock the true potential of the Linux command line.