Search This Blog

Friday, November 30, 2012

Using GNU 'screen'

This is a quick-and-dirty GNU screen cheat-sheet

Start a screen session:
$ screen
(this will also open a window attached to the current screen)
You can also name a screen when opening it, which makes the re-attachment easier, specially if you use many screens simulatneously:
$ screen -S 

In a screen session you can work with multiple windows.

  • Open a new window: ctrl-a and then c
  • Go to the next window: ctrl-a and then n
  • Go to the previous window: ctrl-a and then p

Windows can be closed (killed) or detached. When detached, the process keeps running, but is not attached to the screen anymore. That way, when you quit the screen session, all detached windows will keep running any processes they were running (if you are working on a remote machine, you can logoff and they will keep running!)

Closing and detaching:

  • Close the current window: ctrl-a and then k
  • Close the screen: ctrl-a and then \ (note that this will kill all windows!)
  • Detach a screen session: ctrl-a and then d

You can list all the screens running in a machine (useful when leaving long processes running in remote machines):
$ screen -ls
(this will list all the screen sessions running, each one with a unique ID)

To re-attach a detached window:
$ screen -r <screen_unique_ID|screen_name>

If you need more help inside a window session: ctrl-a and then ?

A more comprehensive cheat-sheet can be found here.

Screen window as a login shell

Add shell -$SHELL to ~/.screenrc

No comments:

Post a Comment