Skip to content

Instantly share code, notes, and snippets.

@arthuralvim
Last active March 24, 2020 11:48
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save arthuralvim/22a2553ba18e014ed07d9cc067f36569 to your computer and use it in GitHub Desktop.
Save arthuralvim/22a2553ba18e014ed07d9cc067f36569 to your computer and use it in GitHub Desktop.
GNU Screen Commands

Screen Commands

On the command prompt, type screen. Run the desired program. Use the key sequence ctrl-a + ctrl-d to detach from the screen session. Reattach to the screen session by typing screen -r.

List running screen sessions

$ screen -list

or

$ screen -ls

Start a screen session

$ screen

Start a screen session named "bla"

$ screen -S <session_name>

Attach to a dettached screen session named "bla"

$ screen -r <session_name>

Attach to an already attached screen session named "bla"

$ screen -x <session_name>

Flow Example

[ec2-user@ip-111-222-333-123 ~]$ screen -ls
There are screens on:
	2004.pts-0.ip-111-222-333-123	(Detached)
	2042.pts-0.ip-111-222-333-123	(Detached)
2 Sockets in /var/run/screen/S-ec2-user.

[ec2-user@ip-111-222-333-123 ~]$ screen -r 2004
[detached]
[ec2-user@ip-111-222-333-123 ~]$ screen -r 2004
[screen is terminating]
[ec2-user@ip-111-222-333-123 ~]$ screen -r
[screen is terminating]
[ec2-user@ip-111-222-333-123 ~]$ screen -ls
No Sockets found in /var/run/screen/S-ec2-user.

[ec2-user@ip-111-222-333-123 ~]$ screen -S executeLongTimeJob
[detached]
[ec2-user@ip-111-222-333-123 ~]$ screen -ls
There is a screen on:
	2456.executeLongTimeJob	(Detached)
1 Socket in /var/run/screen/S-ec2-user.

[ec2-user@ip-111-222-333-123 ~]$ screen -S anotherLongTimeJob
[detached]
[ec2-user@ip-111-222-333-123 ~]$ screen -ls
There are screens on:
	2493.anotherLongTimeJob	(Detached)
	2456.executeLongTimeJob	(Detached)
2 Sockets in /var/run/screen/S-ec2-user.

[ec2-user@ip-111-222-333-123 ~]$ screen -r anotherLongTimeJob
[screen is terminating]
[ec2-user@ip-111-222-333-123 ~]$ screen -r
[screen is terminating]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment