..and then still be able to return to the same session/screen after restarting the terminal machine. I've tried screen but once I restarted my computer screen -d showed no sessions. Nohup seems to be what I want, but then I lose the ability to see the output later on, other than by saving it to a file. Cannot I pretend more?


Screen should work fine. Give more details about what you are doing. Common commands:

# reattach session and if necessary detach it first.
# If there is only one session, sessionname is not necessary.
$ screen -rd sessionname

# list available screen sessions
$ screen -ls

I am not sure why you are using

$ screen -d

All this does is detach a screen session, provided there is only one. Otherwise it will ask which one you want to detach.

I also find

$ echo $TERM

useful to show whether I am actually inside a screen or not, since this is not always obvious. If in a screen, it will return screen. If there are better ways to do this, I'd like to know about them.

  • $ screen -ls No Sockets found in /var/folders/Am/AmQYwuIoFSO0BNhXmOGzQU+++TI/-Tmp-/.screen. But I had detached sessions before turning off my machine, how do I attach to them again now? – simpatico Mar 19 '11 at 17:16
  • @simpatico: Strange. It wouldn't actually matter whether you detached the sessions before turning off your local machine, as long as they were running on the remote machine. You are certain you are running this command on the remote machine and that the earlier screen sessions were on the remote machine? (No offense intended.) I suggest you take a few minutes and try it again. – Faheem Mitha Mar 19 '11 at 17:20
  • @simpatico: by the way, if you want someone to be notified of your comment, prefix it with @username. – Faheem Mitha Mar 19 '11 at 17:21
  • I execute $ screen -ls on my terminal. Before $ screen -d == $ screen ls, since I had multiple screens. N offense, is there how I could execute the command with some log to prove/track things? – simpatico Mar 19 '11 at 17:23
  • @simpatico: not following all of the comment,sorry. You can enable log for a screen session from inside the session with `C-a H'. See the documentation. Again, prefix if you want someone to be notified of your comment. – Faheem Mitha Mar 19 '11 at 17:28

I think that you were on the right way, screen is what you want and not nohup. As you said with nohup you cannot change the settings get your environment back after logging out the remote server. screen supports that. Look in this tutorial. Basically what you need is:

ssh machine

Ctrl-a c


Ctrl-a d

ssh machine
screen -ls
10176.blahblah  (blah)  (Detached)
screen -r 10176
  • In general, screen -DR is the simplest way to reattach your last session. – glenn jackman Mar 19 '11 at 17:46
  • Sure, but it's nice to demonstrate screen -ls because he will need it at some point after starting creating many sessions on the remote server :) – sakisk Mar 19 '11 at 17:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.