Screen-Terminal Multiplexer (GNU)

Screen-Terminal Multiplexer (GNU)

Screen enables you to run several separate shell sessions simultaneously within one terminal window.

GNU Screen is a terminal multiplexer that allows you to create, manage, and navigate between multiple terminal sessions from a single window or remote terminal connection


GNU Screen

GNU Screen is a terminal multiplexer that allows you to create, manage, and navigate between multiple terminal sessions from a single window or remote terminal connection.

  • Terminal Multiplexer: Screen enables you to run several separate shell sessions simultaneously within one terminal window. This means you can have different tasks or programs running in distinct sessions and switch between them easily.
  • Session Persistence: One of Screen’s most valuable features is the ability to detach from a session and leave it running in the background. You can later reattach to the session, even from a different location or after reconnecting via SSH.

Features

  • Multiple Sessions: Create multiple terminal windows (or “screens”) within a single instance and switch among them without opening new terminal windows.
  • Detaching and Reattaching: You can detach a session (using Ctrl+A D) to let processes continue running while you disconnect, and later reattach using screen -r.
  • Session Sharing: Screen allows you to share a session with other users, which is useful for collaborative work or debugging.
  • Scrollback Buffer: It provides a scrollback history so you can review previous output even if it has scrolled off the screen.
  • Customizability: You can configure Screen through a .screenrc file to set keybindings, window names, and other behaviors.

Basic Commands

  • Start Screen (launches a new screen session):
screen -S myappname
  • Detaching a Session: Press Ctrl+A then D to detach the current session, leaving it running in the background.

  • List Sessions:

screen -ls
  • Reattaching to a Session:
screen -r myappname

This command reattaches to the most recent detached session. If there are multiple sessions, you might need to specify the session ID.

  • Creating New Windows: Once inside a screen session, press Ctrl+A then C to create a new window.
  • Switching Windows: Cycle through windows using Ctrl+A then N (next) or Ctrl+A then P (previous).

Use Cases

  • Remote Work: When working over SSH, you can detach your session and safely log out without stopping your long-running processes.
  • Development and Monitoring: Developers often use Screen to run development servers, monitor logs, or execute commands concurrently in separate windows.
  • System Administration: Administrators can manage multiple tasks or monitor different services within a single session, improving efficiency and organization.