Linux SCREEN Command

To start with, apt-get install screen on your favorite Debian server.

For the purposes of this tutorial (and throughout the site), ‘^C’ refers to Ctrl+C, ‘^A’ to Ctrl+A etc.

Now run screen with: screen

You are now within a virtual terminal. Typing exit will close your virtual terminal, and as it is the only virtual terminal open, also terminate the screen command.

Run screen again. Now within the screen type watch -n 1 ps aux – although outside the scope of this screen tutorial, this command will issue ‘ps aux’ to show the running process list every second. Let’s assume that we want to leave this running. Now type ^A, D – this will detach from your screen and you should see “[detached]” on your terminal. You are now back to your terminal, with screen still running.

Type screen -x to reconnect back to your screen session, and you will notice that your watch/ps processes are still running.

Type ^A, C and you will create a new ‘window’ within your same screen session. You can create as many windows as you wish, and the type exit to close them.

You can use ^A, 0 where 0 is your window number to switch between windows within your screen. When your last window is closed, screen will terminate.


Contributed by Reader Phil:

* CTRL + A + p for previous screen
* CTRL + A + n for next screen
* CTRL + A + A to name screen
* CTRL + a + S split screen
* CTRL + a + TAB change screen
* CTRL + a + q close split screen

And you also can modify your .screenrc to add a status bar:
hardstatus alwayslastline
hardstatus string ‘%{= kG}[ %{G}%H %{g}][%= %{=kw}%?%-Lw%?%{r}(%{W}%n*%f%t%?(%u)%?%{r})%{w}%?%+Lw%?%?%= %{g}][%{B}%Y-%m-%d %{W}%c %{g}]‘

I hope you’ve found this helpful

Tagged with: , , , , , , ,
Posted in Linux
2 Comments » for Linux SCREEN Command
  1. Phil says:

    Hello,

    you can also use:
    * CTRL + A + p for previous screen
    * CTRL + A + n for next screen
    * CTRL + A + A to name screen
    * CTRL + a + S split screen
    * CTRL + a + TAB change screen
    * CTRL + a + q close split screen

    And you also can modify your .screenrc to add a status bar:
    hardstatus alwayslastline
    hardstatus string ‘%{= kG}[ %{G}%H %{g}][%= %{=kw}%?%-Lw%?%{r}(%{W}%n*%f%t%?(%u)%?%{r})%{w}%?%+Lw%?%?%= %{g}][%{B}%Y-%m-%d %{W}%c %{g}]‘

  2. Adam Palmer says:

    Thanks very much for the contribution Phil – this is really good. I’ve edited the post with your information.

Leave a Reply