CLI Screen Guide

linux cli

The screen command in Linux allows users to manage multiple terminal sessions within a single window, facilitating remote access and session persistence.

Using Screen

  1. Start a new screen session:

    screen
  2. Detach from the current screen session: Press Ctrl + A, then Ctrl + D.

  3. List existing screen sessions:

    screen -ls
  4. Reattach to a detached screen session:

    screen -r [session_id]
  5. Create a named screen session:

    screen -S [session_name]
  6. Reattach to a named screen session:

    screen -r [session_name]
  7. Switch between multiple windows within a screen session: Press Ctrl + A, then n for next window or p for previous window.

  8. Split the screen horizontally: Press Ctrl + A, then S.

  9. Split the screen vertically: Press Ctrl + A, then |.

  10. Navigate between split screens: Press Ctrl + A, then Tab.

  11. Open shell on new screen split: Press Ctrl + A, then c.

  12. Close the current window or screen: Press Ctrl + A, then k.

  13. Exit the screen session: Inside the screen session, type exit.

  14. Run a command in a new screen session:

    screen -dmS [session_name] [command]
  15. Send a command to a running screen session:

    screen -S [session_name] -X stuff '[command]\n'
  16. Attach to a running screen session and run a command:

    screen -S [session_name] -X stuff '[command]\n'
  17. Attach to a running screen session that already says Attached (for instance if your previous ssh connection failed):

    screen -rd

Note: Replace [session_id], [session_name], and [command] with the actual session ID, session name, and command, respectively.

Next Post Previous Post