How to use shortcuts for screen command.

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.
  1. Basic Usage of screen

To initiate a new screen session, simply type:

screen

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.

  1. 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:

screen -ls

The output will display a list of available sessions along with their unique session IDs. To reattach to a specific session, use:

screen -r session_id
  1. 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:

screen -S my_session

Now, you can reattach to this session by using its name instead of the session ID:

screen -r my_session
  1. 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:

Ctrl + A, C

To switch between different windows, use:

Ctrl + A, N (Next window)
Ctrl + A, P (Previous window)

If you want to switch directly to a specific window, press:

Ctrl + A, <number>
  1. 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.

  1. 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:

Ctrl + A, |

To split the screen horizontally, use:

Ctrl + A, S

Switch between split screen regions by pressing:

Ctrl + A, Tab
  1. Copy and Paste

screen also allows you to copy and paste text between different windows within a session. To enter copy mode, press:

Ctrl + A, [

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:

Ctrl + A, ]
  1. Exiting screen Sessions

To exit a screen session, ensure that all windows within the session are closed. Then, type:

exit

This will terminate the screen session.

 

Conclusion:

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.