Skip to content

Instantly share code, notes, and snippets.

@gmolveau
Last active May 26, 2021 08:09
Show Gist options
  • Save gmolveau/08df11308ef20fa136bb0d6afd28b822 to your computer and use it in GitHub Desktop.
Save gmolveau/08df11308ef20fa136bb0d6afd28b822 to your computer and use it in GitHub Desktop.
[Screen usage guide] examples on how to use screen on linux #screen #linux #server #background
  • Create a new screen with screen -S name_screen or screen (this will generate an ID of screen)

  • OR launch your_command directly with screen -S name_of_screen your_command

  • then detach it by pressing Ctrl+A then d


  • OR launch and detach immediatly with screen -S name_of_screen -dm your_command

  • you're now back at your main terminal

  • you can list your screens by typing screen -ls

  • and re-attach your screen by its name with screen -r name_of_screen

  • to scroll a re-attached screen press Ctrl+a then key Escape -> you can now move with the arrow keys and press Return twice to go back to the end

  • delete a detached screen with screen -X -S name_of_screen quit


Example :

$ screen -S ping
$ ping 1.1.1.1

# Ctrl + A then press D
# [detached]

$ screen -ls
# There is a screen on:
#    27086.ping  (Detached)
# 1 Socket in /var/folders/5l/_m6dn0vj3n556cw2fjd923200000gn/T/.screen.

$ screen -r ping

# PING 1.1.1.1 (1.1.1.1) 56(84) bytes of data.
# [...]
# 64 bytes from 1.1.1.1: icmp_seq=11 ttl=59 time=2.63 ms
# 64 bytes from 1.1.1.1: icmp_seq=12 ttl=59 time=2.53 ms
# 64 bytes from 1.1.1.1: icmp_seq=13 ttl=59 time=2.48 ms

# Ctrl + A then press D
# [detached]

$ screen -X -S ping quit

$ screen -ls
# No Sockets found in /var/folders/5l/_m6dn0vj3n556cw2fjd923200000gn/T/.screen.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment