Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

How do you use the "screen" command effectively?
Is it:

  1. Type "screen"

  2. Type in command

  3. Lose connection

  4. Check back on lost session

How do I carry out step 4?

share|improve this question

migrated from Aug 17 '09 at 23:14

This question came from our site for professional and enthusiast programmers.

 For windows system

 Open putty 
 then login in server

If you want to see screen in Console then you have to write command

 Screen -ls

if you have to access the screen then you have to use below command

 screen -x screen id
share|improve this answer

Step 4 is "screen -r"

If you got disconnected really forcefully, you might need to do "screen -r -d", to force it to disconnect from your old ssh session, which it thinks is still open.

share|improve this answer

you can also set up your environment to log you in and start screen right off the bat. There are many ways to do it. I chose to add this to my .bashrc file.

# screen management
if [ $SSH_TTY ] && [ ! $WINDOW ]; then
  SCREENLIST=`screen -ls | grep 'Attached'`
  if [ $? -eq "0" ]; then
    echo -e "Screen is already running and attached:\n ${SCREENLIST}"
    screen -U -R
share|improve this answer

screen -dr to detach and resume the previous screen session.

share|improve this answer

You'd be looking for

screen -x
share|improve this answer

A quick Google search found this screen guide

So from step b) you can detach the screen using :

"Ctrl - A" "d"

and then later after the connection has been lost and your connected once again find the screen using :

# screen -ls

and then reattach using :

# screen -r <screen_session_name>

share|improve this answer

With screen:

  1. 'screen'
  2. type 'command'
  3. 'ctrl-A-D' to detach from the screen
  4. logoff from the session
  5. 'screen -RD' to reattach to the screen (if there's more than one you'll get a list of current screen sessions and you'll have to supply the session number) from a new session

A simpler method that is useful for commands that leave logfiles or just throw some relevant output and do not need interactivity is nohup:

  1. 'nohup command > logfile &'
  2. logoff from the session
  3. 'tail -f logfile' from a new session
share|improve this answer

Here's what I have picked up about using screen (which I, too, have just started doing):

  • screen -S <name> creates a screen named '<name>'. This is quite useful if you want to have several screen sessions going at the same time. For instance, I have one I use normally and one I use for my persistent processes.
  • screen -ls lists the running screens.
  • screen -r <name> resumes a detached screen. If the screen is already attached somewhere, use screen -dr <name>.

Also, when you start using screen, whenever you plan to leave, press ^a d (= ctrl-a followed by a d) to detach the screen you're currently running. It can then be resumed later.

In addition, I can recommend taking a look at ^a ? for a list of the different commands you can use while inside of a screen.

The most important of these (to me) are:

  • ^a c to create a new window in your screen session.
  • ^a ^a to switch between the two last used windows.
  • ^a " to list the current windows in your session.
  • ^a Esc to scroll in your screen buffer.
  • ^a k to kill the current window.
  • ^a x to lock your screen session, in case you need to leave your computer and don't want people to mess with it.
share|improve this answer

Screen is really powerful, and allows you to do exactly what you asked.

To see all your sessions, type

screen -list

Once you've identified a screen session to reconnect too, try

screen -dr SCREENID

which will nicely detach and re-attach your session.

You can also do a less nice,

screen -D -R

which will detach and logout remotely, if nesscessary, then reattach, or if that session doesn't exist, it will create it and notify the user. You can add a "-t NAME" to give shells or programs a title.

Within screen, use


to create a new window (So you don't need 4000000 screen sessions to disconnect and reconnect from), and change between them with


Indexing from 0, of course:P

Since you seem a bit unfamiliar with screen, I'm going to assume you could use some other info. I like the following commands, like:

-e xy

Which causes x to be the command character and y to be the character to generate a literal command character. The defaults are Ctrl-a and `a.

There's some more for you here: Screen! It's what's for programmers

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.