screen -S main
screen
:screen
is terminal multiplexer that allows you to run multiple terminal sessions within a single terminal window. It's particularly useful when you want to keep processes running even after you disconnect from a remote server or terminal. It's commonly used for managing and organizing multiple processes or tasks in a Unix-like environment.-S main
: The-S
option followed by a session name (in this case, "main") is used to create a newscreen
session and assign it a specific name. This is beneficial when you have multiplescreen
sessions, as it makes it easier to identify and reconnect to the desired session later.
- If a
screen
session with the name "main" already exists, you will be reattached to that session. - If no
screen
session with the name "main" exists, a new session named "main" will be created.
Once inside the screen
session, you can run commands and start processes. To detach from the screen
session and leave it running in the background, you can press Ctrl + A
followed by Ctrl + D
. Later, you can reattach to this session using the screen -r
command.
This command is especially useful for running long-term processes or tasks that you want to keep running even when your terminal connection is closed. The session name ("main" in this case) helps you identify and manage your screen
sessions effectively.
screen -ls
-ls
: The-ls
option is used to list all thescreen
sessions that are currently running or detached. It provides information about the availablescreen
sessions, including their session names and statuses.
- The terminal will display a list of
screen
sessions, including their session names, status (whether attached or detached), and other details. Example output:In this example, there is aThere is a screen on: 12345.main (Detached) 1 socket in /run/screen/S-your_username.
screen
session named "main" with the session ID (12345) and the status "Detached". - If there are no
screen
sessions, the output will indicate that there are no sockets found.
This command is helpful for checking the status and names of existing screen
sessions. It allows users to identify active sessions, their statuses, and choose which session to reattach to or manipulate further.
Using the mehodology of "check, change, check" we can start a screen
session by:
screen -ls
This checks if any screen
sessions are open. Now we can change or open a new screen
session with:
screen -S main
Lastly, check the screen
session to make sure it is working properly:
screen -ls
Keyboard shortcuts within a screen
session:
Ctrl + a
:- Purpose: Command prefix.
- Usage: Prefix for most other
screen
commands
Ctrl + a + c
:- Purpose: Create a new shell session (window).
- Usage: Opens a new shell session within the current
screen
window.
Ctrl + a + n
:- Purpose: Switch to the next window.
- Usage: Move to the next shell session (window) within the
screen
session.
Ctrl + a + p
:- Purpose:Switch to the previous window.
- Usage: Move to the previous shell session (window) within the
screen
session.
Ctrl + a + "
:- Purpose: List and navigate through open windows.
- Usage: Presents a list of open windows for selection.
Ctrl + a + A
:- Purpose: Rename the current window.
- Usage: Allows you to assign a specific name to the current shell session (window).
Ctrl + a + d
:- Purpose: Detach from the current
screen
session. - Usage: Leaves the
screen
session running in the background.
- Purpose: Detach from the current
Ctrl + a + [ or Space
:- Purpose: Enter copy mode.
- Usage: Allows you to scroll and copy text within the
screen
session.
Ctrl + a + ]
:- Purpose: Paste copied text.
- Usage: Pastes the text copied in copy mode.
Ctrl + a + \
:- Purpose: Kill the current window.
- Usage: Closes the current shell session (window).
Ctrl + a + S
:- Purpose: Split the current region horizontally.
- Usage: Divides the window into two horizontal regions.
Ctrl + a + Tab
:- Purpose: Switch focus to the next region.
- Usage: Moves the focus between split regions
These are just a few of the many screen
keyboard shortcuts. The flexibility of screen
allows users to manage multiple sessions, windows, and panes efficiently. For more details, you can refer to the screen
manual (man screen
) or online resources.