📺 Command: screen (The Terminal Multiplexer)
The screen command is a full-screen window manager that multiplexes a single physical terminal between several processes. It allows you to start a process, "detach" from it, and "re-attach" later—even if you've logged out or changed machines.
1. The "Why"
While nohup is good for one-off background tasks, screen is for interactive work.
- Multi-tasking: Open multiple "windows" inside a single terminal window. One can be your VS Code terminal, another your
journalctllogs, and a third forpacmanupdates. - Crash Protection: If your Arch Linux terminal emulator (like Alacritty or Kitty) crashes, your
screensession keeps running in the background.
2. Basic Syntax & Workflow
A. Starting a Session
Give your session a name so it's easy to find later:
screen -S dev_session
B. The "Magic" Escape Key
Almost every screen command starts with Ctrl + a.
- Detach: Press
Ctrl + athend. You are now back in your main terminal. The session is still running. - New Window: Press
Ctrl + athenc. - Switch Windows: Press
Ctrl + athenn(next) orp(previous).
3. Management Commands
| Action | Command |
|---|---|
| List Sessions | screen -ls |
| Re-attach | screen -r [name] |
| Force Re-attach | screen -D -r [name] (Used if a session is still "attached" elsewhere) |
| Kill Session | Inside the session, type exit or press Ctrl + d. |
4. Practical Examples for Your Workflow
A. The Long Compilation
If you're compiling a large project for Ahmed Codes:
- Type
screen -S build. - Start your build command (e.g.,
./gradlew build). - Press
Ctrl + a, thend. - Go have coffee. Your Ryzen 5 will keep working. When you return, type
screen -r build.
B. Remote Server Management
If you are managing your Supabase backend or a remote server:
- SSH into the server.
- Start
screen. - If your internet drops, the server-side process won't stop. Just log back in and type
screen -r.
5. screen vs. tmux
You might hear people talk about tmux.
screen: Older, simpler, and installed by default on almost every Linux system.tmux: More modern, has better status bars, and handles vertical/horizontal splits much more intuitively.
6. Pro-Tips
- Scrollback Mode: To scroll up in a screen session, press
Ctrl + athen[. Use your arrow keys orPage Up/Downto look at history. PressEscto return to live mode. - Arch Linux Context: You can use
screento connect to serial ports (like an Arduino or specialized hardware). For example:screen /dev/ttyUSB0 115200. - Tutorial Writing: When teaching others about persistent processes,
screenis a great tool to showcase because of its "visual" nature compared to the "invisible"nohup.
7. Summary Reference
| Goal | Shortcut / Command |
|---|---|
| Start Named Session | screen -S [name] |
| Detach | Ctrl + a, then d |
| Re-attach | screen -r [name] |
| List all | screen -ls |
| Scroll/Copy mode | Ctrl + a, then [ |